服务端:
#!/usr/bin/env python# -*- coding: utf-8 -*-import socketphone = socket.socket(socket.AF_INET, socket.SOCK_STREAM)phone.bind(('192.168.1.113', 8090))phone.listen(10)connt , client = phone.accept()print('starting ....')print(client)while True: data = connt.recv(1024) print( data.decode('utf-8')) msg = input('>>>:').strip() connt.send(msg.encode('utf-8'))connt.close()phone.close()客户端:
#!/usr/bin/env python# -*- coding: utf-8 -*-import socketphone1 = socket.socket(socket.AF_INET,socket.SOCK_STREAM)phone1.connect(('192.168.1.113',8090))while True: msg = input('>>>:').strip() phone1.send(msg.encode('utf-8')) data1 =phone1.recv(1024) print(data1.decode('utf-8'))phone1.close()