socket基础编程-2

时间:2022-05-11 13:52:02

client端:

 import socket
while True:
client=socket.socket(socket.ANET,socket.SOCK_STREAM)
client.connet(('localhost',8080))
input_data=input('Input_data:')
client.send(input_data.encode())
data=client.recv(1024)
print(data) client.close()

server端:

import socketserver
class mytcpserver(socketserver.BaseRequestHandler):
def handle(self):
self.data=self.request.recv(10240)
print(self.data)
        print('客户端地址:',self.client_address[0])
     

        self.request.send(self.data.upper())

if __name__ =='__main__':

    h,p='localhost',8080
server=socketserver.ThreadingTCPServer((host,post),mytcpserver)
server.serve_forever()