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

python socket编程 TCP

时间:2014-12-10 18:05:13      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:python   socket   

python socket编程 TCP

by wuxy

server.py
import socket
import commands

BUF_SIZE = 1024
server_addr = ('127.0.0.1',8888)
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(server_addr)
server.listen(5)
while True:
	client,client_addr = server.accept()
	print 'Connected by',client_addr
	while True:
		data = client.recv(BUF_SIZE)
		print data
		client.sendall(data)
server.close()

client.py
import socket

BUF_SIZE = 1024
server_addr = ('127.0.0.1',8888)
client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(server_addr)
while True:
	data = raw_input("Please input some string > ")
	client.sendall(data)
	data = client.recv(BUF_SIZE)
	print data
client.close()


python socket编程 TCP

标签:python   socket   

原文地址:http://blog.csdn.net/rainlesvio/article/details/41848853

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