//服务器
import socket
from threading import *
server = socket.socket()
server.bind(('10.7.181.70', 8089))
server.listen(512)
class Duoren(Thread):
def run(self) -> None:
while True:
connect, address = server.accept()
while True:
recv_data = connect.recv(1024)
print('接收来自%s的消息:'% str(address), str(recv_data, encoding='utf-8'))
send_message = input('服务器:')
connect.send(send_message.encode())
if name == 'main':
t1 = Duoren()
t2 = Duoren()
t1.start()
t2.start()
//客户端(多个)
from socket import socket
client = socket()
client.connect(('10.7.181.70', 8089))
while True:
message = input('客户端:')
client.send(message.encode())
re_data = client.recv(1024)
print(re_data.decode(encoding='utf-8'))