1
import socket
host = socket.gethostname()
port=8081
serversock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
serversock.bind((host,port))
serversock.listen(5)
print('等待客户端连接')
while True:
clientsocket,addr=serversock.accept()
data = clientsocket.recv(1024)
print(data)
msg='hello'
clientsocket.sendall(msg.encode('utf-8'))
clientsocket.close()
2
import socket
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = socket.gethostname()
port=8081
sock.connect((host,port))
senddata=input("请输入:")
sock.send(senddata.encode())
recedata=sock.recv(1024)
print(recedata.decode("utf-8"))
sock.close()
© 版权声明
THE END
暂无评论内容