server端:
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 print c.recv(1024) c.send('Thank you for your connection') c.close()
2. 客户端
import sockets = socket.socket()host = socket.gethostname()port = 1234s.connect((host, port))s.send('nihao')print s.recv(1024)
同时在一台计算机上运行,可以观察到效果。