Python套接字服务器端口转发与ngrok



我正在用python, sockets制作一个cli-chat系统。当服务器和客户端在同一台机器上时,代码可以正常工作。

但是现在我正在尝试用ngrok来转发我的本地服务器,以便与远程客户端聊天。

当客户端想要连接时,他必须给服务器url。如果我给我的localhost url,客户端连接到套接字服务器,一切工作正常。

但是每当我给ngrok的tcp隧道url,它不工作,并抛出下面的错误

Traceback (most recent call last):
File "/storage/emulated/0/Sun/Python/cmd-chat/user.py", line 5, in <module>
client.connect((serverUrl, 5000))              #connecting client to server
socket.gaierror: [Errno 7] No address associated with hostname

我作为输入给出的url是,tcp://x.tcp.ngrok.io:17xxx

嘿,我想我知道你错在哪里了

# Your Server Url should be
serverUrl = hostAddress = "x.tcp.ngrok.io"
# The Port in which we want to connect to the server Should be
port = 17234 # The number given in the end of URL link

最新更新