我一直在尝试创建一个简单的套接字程序。This is my code:def send(message): HOST = "localhost" PORT = 123 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.accept((HOST, PORT)) text = message.encode('utf-8') s.sendall(bytes(text)) print("printing from send func", repr(text))def receive(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.accept(("localhost", 1234)) while True: msg = s.recv(1024) dmsg = msg.decode('utf-8') if len(dmsg) > 60: print(dmsg) return dmsg我有一个 server.py 代码,我的服务器已启动并正在运行。每次我向服务器发送内容时,我都应该收到一条 hello world 消息,但它并没有发生。
添加回答
举报
0/150
提交
取消