socketserver

import socketserver


class MySocket(socketserver.StreamRequestHandler):
def handle(self):
conn = self.request
add = self.client_address

while True:
accept_data = str(conn.recv(1024), encoding='utf-8')
print(accept_data)
send_data = bytes(input(">>>>>"), encoding="utf8")
conn.sendall(send_data)


if __name__ == '__main__':
sever = socketserver.ThreadingTCPServer(('127.0.0.1', 8888), MySocket)
sever.serve_forever()






import socket

sock=socket.socket()
sock.connect(('127.0.0.1',8888))

while True:
sock.sendall(bytes('456',encoding="utf8"))
accept_data=str(sock.recv(1024),encoding="utf8")
print(accept_data)
posted @ 2018-06-06 23:03  糖宝虫  阅读(137)  评论(0编辑  收藏  举报