简单的socket编程

服务端

import
socket s = socket.socket() host = socket.gethostname() port = 1234 s.bind((host, port)) s.listen(5) while True: c, addr = s.accept() print('Got connection from', addr) c.send('Thank you for connecting') c.close()
客户端
import socket
s = socket.socket()
host = socket.gethostname()
port = 1234
s.connect((host, port))
print(s.recv(1024))

原文地址:https://www.cnblogs.com/xinjing-jingxin/p/9522085.html