freedom_wings
freedom_wings
2016-04-12 14:07

python,socketserver的问题,求指导

  • socket
  • 网络编程

server.py

 import socketserver
from socketserver import  StreamRequestHandler
from socketserver import ThreadingTCPServer

addr=('localhost',9101)
class MySocketServer(StreamRequestHandler):
    def handler(self):
        while True:
            receive_data=self.request.recv(4096)
            print("接收到的数据是:%s" % receive_data)
            self.request.send(b"this is the reply from the server")




server=ThreadingTCPServer(addr,MySocketServer)
server.serve_forever()

client.py

 import socket

addr=('localhost',9101)
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(addr)
client.send(b'here is client\n')
data=client.recv(4096)
print(data)

先运行server,再运行client,结果如下,第一张是客户端,第二张是服务端:
图片说明
图片说明
由图看出,服务端收不到客户端的消息,客户端不知从哪里接收了空的字符串,求大神指导指导

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换