标签:
socket单进程服务器
[root@localhost ~]# cat echoserver.py
import socket
host=‘192.168.10.101‘
port=9657
s=socket.socket()
s.bind((host,port))
s.listen(1)
conn,addr=s.accept()
print ‘connected by‘,addr
while 1:
data=conn.recv(20)
if not data:break
conn.sendall(data)
s.close()
python echoserver.py
fgy@fgy-QTH6:~/Documents/python$ cat echoclient.py
import socket
host=‘192.168.10.101‘
port=9657
s=socket.socket()
s.connect((host,port))
s.sendall(‘hello,world‘)
data=s.recv(1024)
print ‘received‘,repr(data)
s.close()
python echoclient.py
标签:
原文地址:http://www.cnblogs.com/createyuan/p/5742092.html