使用 WebSockets 使用 Tornado 获取客户端端口号 [英] Get client port number using tornado using WebSockets

查看:34
本文介绍了使用 WebSockets 使用 Tornado 获取客户端端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以获得客户端IP:

I can get client ip:

self.request.remote_ip 

我还可以从 RequestHandler 获取客户端端口号:

I can also get client port number from RequestHandler:

self.request.connection.stream.socket.getpeername()[1]

(感谢这个)

但是来自 WebSocket 的客户端端口号呢?

But what about client port number from WebSocket?

我在文档中找不到有关如何执行此操作的任何信息.我已经通过源代码看了很长时间,但仍然无法弄清楚它在哪里.

I can't find anything on how to do this in the docs. I have had a long look through the source but still can't figure out where it is.

推荐答案

正如我在 如何在RequestHandler中获取客户端端口?,第一个问题是你为什么要这个?

As I said in How to get the client port in RequestHandler?, the first question is why do you want this?

在 websocket 处理程序中,与您在上面发布的代码等效的是 self.stream.socket.getpeername()[1].

In a websocket handler, the equivalent to the code you've posted above is self.stream.socket.getpeername()[1].

这篇关于使用 WebSockets 使用 Tornado 获取客户端端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆