期待像风一样的自由

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:

散步的SUN的个人空间 引用 删除 散步的SUN   /   2012-01-06 16:38:35
天天学习python啊
 

评分:0

我来说两句

Open Toolbar