我一直在嘗試創(chuàng)建一個(gè)簡(jiǎn)單的套接字程序。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我有一個(gè) server.py 代碼,我的服務(wù)器已啟動(dòng)并正在運(yùn)行。每次我向服務(wù)器發(fā)送內(nèi)容時(shí),我都應(yīng)該收到一條 hello world 消息,但它并沒(méi)有發(fā)生。
無(wú)法使用pysockets從服務(wù)器接收消息
開(kāi)心每一天1111
2023-06-13 15:17:33