我将在两台不同的Windows 7机器上通过Python 2.7中的套接字(Socket)运行服务器和客户端,并使它们在同一网络中运行。首先,我只是想让它们连接成功,然后再尝试进行其他操作。
目前我的服务器代码如下:
import socket
host = '0.0.0.0' #Also tried '', 'localhost', gethostname()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, 12345))
s.listen(5)
cs, addr = s.accept()
print "Connected."
我的客户是:
import socket
host = '127.0.0.1' #Also tried 'localhost', gethostname()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(host, 12345)
print "Connected."
我得到的错误是:
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it.
我查看了很多其他问题,但没有一个答案能解决我的问题。非常感谢您的帮助。
当我将服务器的IP地址(10.0.63.40)用作客户端的主机时,出现了以下情况:
[Errno 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