我一直在嘗試創建一個簡單的套接字程序。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
提交
取消