期待像风一样的自由
python---Socket通信demo
上一篇 /
下一篇 2011-10-15 00:23:25
/ 个人分类:PythonDemo
###################
##client demo
###################
#!/usr/bin/pyhton
#-*- coding: utf-8 -*-
__metaclass__=type #new type
import socket
s=socket.socket()
host=socket.gethostname()
port=1234
s.connect((host,port))
print s.recv(1024)
####################
##Server demo
####################
#!/usr/bin/pyhton
#-*- coding: utf-8 -*-
__metaclass__=type #new type
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!')
c.close()
收藏
举报
TAG: