【发布时间】:2021-05-04 19:17:24
【问题描述】:
我正在关注this 教程,因为我一般对 TCP 或网络不太了解,它可以在 localhost 上运行,但是当我将其切换到我的真实 IP 并请我的朋友试用客户端时在他的系统上,它没有连接,给出错误:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
如果它因为“WinError”部分而在这里很重要,我在 Ubuntu 上,我的朋友在 Windows 上。
server.py
import socket
HOST = 'my ip'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
client.py
import socket
HOST = '86.184.147.101'
PORT = 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b'Hello, world')
data = s.recv(1024)
print('Received', repr(data))
我认为这可能只是一些显而易见的事情,但我在 stackoverflow 或互联网的其他部分找不到任何相关问题。干杯!
【问题讨论】:
标签: python sockets networking tcp