Huy*_*ynh 6 websocket python-3.x handshake
我正在学习 websocket 在 python 3 中的工作原理。我在 websocket 源代码中添加了 print(sock) 到 _handshake.py 的 def 握手,以了解 sock 中的消息是什么,结果是这样的:
Print out sock:<ssl.SSLSocket fd=508, family=AddressFamily.AF_INET, type=0, proto=0, laddr=('192.168.1.2', 58730), raddr=('202.160.125.211', 443)>
Run Code Online (Sandbox Code Playgroud)
我想知道 laddr 和 raddr 是什么?我知道这太基础了,但没有扎实的背景,因为我似乎很难理解我已经在 gg 中搜索了这些关键字,但没有解释。
def handshake(sock, hostname, port, resource, **options):
headers, key = _get_handshake_headers(resource, hostname, port, options)
header_str = "\r\n".join(headers)
send(sock, header_str)
dump("request header", header_str)
print("Print out sock:{}".format(sock))
status, resp = _get_resp_headers(sock)
if status in SUPPORTED_REDIRECT_STATUSES:
return handshake_response(status, resp, None)
success, subproto = _validate(resp, key, options.get("subprotocols"))
if not success:
raise WebSocketException("Invalid WebSocket Header")
return handshake_response(status, resp, subproto)
Run Code Online (Sandbox Code Playgroud)