python socket单工聊天工具,pythonsocket单工,socket单工聊天工具
python socket单工聊天工具,pythonsocket单工,socket单工聊天工具
socket单工聊天工具
####client####from socket import *HOST='localhost'PORT=21567BUFSIZ=1024ADDR=(HOST,PORT)while True: tcpCliSock=socket(AF_INET,SOCK_STREAM) tcpCliSock.connect(ADDR) data=raw_input('input your words:') if not data: break tcpCliSock.send('%s\r\n' %data) data='......['+str(tcpCliSock.getsockname())+tcpCliSock.recv(BUFSIZ) if not data: break print data.strip() print tcpCliSock.close()####server####from SocketServer import (TCPServer as TCP,StreamRequestHandler as SRH)from time import ctimeHOST=''PORT=21567ADDR=(HOST,PORT)class MyRequestHandler(SRH): def handle(self): #print '...connect form...',self.client_address print '......[%s%s]:%s' %(self.client_address,ctime(),self.rfile.readline()) inp=raw_input('input you words:') self.wfile.write('%s:]%s' %(ctime(),inp))tcpServ=TCP(ADDR,MyRequestHandler)print 'waitint for connection...'tcpServ.serve_forever()
相关内容
- 用Python编写的列举所有对称日的小程序--菜鸟写的,请
- python监控网卡流量,python监控网卡,[Python]代码im
- Find the coefficients of the polynomial that fits the specified data
- tinyipdate最新ip库 python操作类,tinyipdatepython,发布最新版
- Linux下歌词编辑器,Linux歌词编辑器,#!/usr/bin/e
- 支持编辑的词典,编辑词典,DictForGeeks
- Python倒计时代码,python倒计时,#!/usr/bin/e
- 教师统计学生交作业次数,教师统计作业次数,[Python]代
- select 实现的 socket服务器,selectsocket,[Python]代码im
- python编码,,[Python]代码#
评论关闭