#client端代码 import socket client = socket.socket() client.connect(('127.0.0.1',3999)) while True: content=input('>>>') client.send(bytes(content,'utf-8')) content=client.recv(1024) print(str(content,encoding='utf-8')) client.close()
#server端代码 import socket server = socket.socket() server.bind(('127.0.0.1',3999)) server.listen(7) s, addr = server.accept() print('connect addr: {}'.format(addr)) while True: content=s.recv(1024) if len(content) == 0: break s.send(content) print(str(content,encoding='utf-8')) s.close()
#server端代码标签:addr,Python,server,content,client,print,socket From: https://www.cnblogs.com/yl6688/p/17180627.html
import socket
server = socket.socket()
server.bind(('127.0.0.1',3999))
server.listen(7)
s, addr = server.accept()
print('connect addr: {}'.format(addr))
while True:
content=s.recv(1024)
if len(content) == 0:
break
s.send(content)
print(str(content,encoding='utf-8'))
s.close()