Get client port number using tornado using WebSockets

烈酒焚心 提交于 2019-12-11 20:37:52

问题


I can get client ip:

self.request.remote_ip 

I can also get client port number from RequestHandler:

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

(thanks to this)

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/35492062/get-client-port-number-using-tornado-using-websockets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!