1. 程式人生 > >02 socketserver服務端

02 socketserver服務端

elf tcp nco req utf eve ets spa server

import socketserver

class Myserver(socketserver.BaseRequestHandler):

    def handle(self):
        while 1:
            from_client_msg = self.request.recv(1024)  # self.request = conn
            print(from_client_msg.decode(utf-8))
            msg = input(服務端說:)
            self.request.send(msg.encode(
utf-8)) if __name__ == __main__: ip_port = (127.0.0.1,8001) server = socketserver.ThreadingTCPServer(ip_port,Myserver) server.serve_forever()

02 socketserver服務端