问题
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