码迷,mamicode.com
首页 > 编程语言 > 详细

python socket

时间:2016-02-11 19:13:34      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

服务端

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 for connecting)
c.close()

客户端

import socket
s = socket.socket()
host = socket.gethostname()
port = 1234
s.connect((host, port))
print s.recv(1024)

 

python socket

标签:

原文地址:http://www.cnblogs.com/zhuweiblog/p/5186595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!