簡體   English   中英

Python 使用 ngrok 進行套接字服務器端口轉發

[英]Python socket server port forwarding with ngrok

我正在使用 python、sockets 制作一個 cli-chat 系統。 當服務器和客戶端在同一台機器上時,代碼可以正常工作。

但現在我正在嘗試使用 ngrok 將我的本地服務器端口轉發,以與遠程客戶端聊天。

當客戶端想要連接時,他必須給服務器 url。 如果我給我的本地主機 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

The url I am giving as input is, 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM