完全按视频代码写无法通信
也没有报错什么的,服务端接收不到客户端的消息
也没有报错什么的,服务端接收不到客户端的消息
2020-05-19
server.py
import socket def server(): # 1.Create s = socket.socket() # 2.bind HOST = '127.0.0.1' PORT = 6666 s.bind((HOST,PORT)) # 3.listen s.listen(5) # 4.process while True: c, addr = s.accept() print('Connect client: ', addr) msg = c.recv(1024) print('From client: %s' % msg) c.send(msg) pass if __name__ == '__main__': server()
client.py
import socket def client(): # 1. Create s = socket.socket() # 2. link HOST = '127.0.0.1' PORT = 6666 s.connect((HOST, PORT)) # 3. process s.send(b'Hello World!') msg = s.recv(1024) print('From server: %s' % msg) if __name__ == '__main__': client()
emm, 这是我的,可以正常接受呢,要不你试试这个代码?
举报