#Server
import socket
HOST = ‘‘
PORT = 51234
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(1)
conn,addr = s.accept()
print ‘Connected by‘, addr
while True:
data = conn.recv(1024)
print ‘received:‘,data
if not data:break
conn.sendall(data)
conn.close()
---------------------------------
#client
import socket
HOST = ‘10.10.1.21‘
PORT = 51234
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#s.bind((HOST,PORT))
s.connect((HOST,PORT))
s.sendall("Hello, world!!!")
data = s.recv(1024)
s.close()
print ‘Received‘,repr(data)
原文地址:http://4764055.blog.51cto.com/4754055/1916938