Python:Socket-TCP通信
from socket import * HOST = '172.24.0.17' PORT = 21567 BUFSIZE = 1024 ADDR = (HOST, PORT) tcpCliSock = socket(AF_INET, SOCK_STREAM) tcpCliSock.connect(ADDR) while True: data = input('>') if not data: break tcpCliSock.send(data) data = tcpCliSock.recv(BUFFSIZE) if not data: break print(data) tcpCliSock.close()
以上为Ser、Cli的源代码,源自【Python核心编程2】
运行代码时发现在本机启服务器、客户端时,客户端无法连接到服务器。
connection refused error win errorr 10061
解决方法:关闭所有python的IDLE,再重新运行此代码,此问题消失