简单 demo
Server.py
1234567891011121314
import sockets = socket.socket()host = socket.gethostname()port = 1234s.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()
Client.py
123456789
import sockets = socket.socket()host = socket.gethostname()port = 1234s.connect((host, port))print s.recv(1024)