使用python内建asyncore编写socket client
来源:互联网 发布:python串口编程实例 编辑:程序博客网 时间:2024/04/30 13:36
一般写服务器的时候需要编写一个机器人来辅助自己测试。这里就是使用python内建的库编写一个socket机器人。
'''Created on 2013-3-8@author: Administrator'''import socketimport asyncoreimport structimport loggingimport timeclass TCPClient(asyncore.dispatcher): ''' classdocs ''' def __init__(self): ''' Constructor ''' asyncore.dispatcher.__init__(self) self.send_buf_ = '' self.recv_buf_ = '' self.is_conn_ = False self.ip_ = "localhost" self.port_map_ = 9250 pass ''' network callback function ''' def handle_connect( self ): logging.debug("connect establishment ...") self.is_conn_ = True self.connect_time_ = time.time() pass def handle_close( self ): self.is_conn_ = False logging.debug("handle_close.") self.close() pass def handle_read( self ): sub_buf = self.recv( MAX_RECV_CACHE ) if len(sub_buf) == 0: return self.recv_buf_ = self.recv_buf_ + sub_buf logging.debug("handle_read, recv size: %d"%len(self.recv_buf_)) pass def handle_error(self): logging.debug("handle_error") pass def handle_write( self ): if not self.is_conn_: return logging.debug("handle_write.") sent = self.send( self.send_buf_ ) self.send_buf_ = self.send_buf_[sent:] pass def writable( self ): return (len( self.send_buf_ ) > 0) def readable(self): return True
0 0
- 使用python内建asyncore编写socket client
- python asyncore 使用
- python里使用asyncore模块
- 使用Twisted替换asyncore进行socket编程
- Python--asyncore
- 使用asyncore
- 使用Socket编写Client-Server通信总结
- Python asyncore异步socket封装模块用法总结
- python里使用asyncore创建时间服务客户端
- Python中的asyncore(1)
- asyncore的使用
- Python 编写 FTP Client
- python socket-server-client
- tcp python socket client
- IOS编程Socket Client编写
- Python异步通信模块asyncore
- Python异步通信模块asyncore
- python编写socket
- 获取Linux系统short、int、long等各种数值类型最大最小值
- C语言——关于字符相同,删除字符的代码
- Android Application类的使用
- 性能调优笔记
- 找出没有出现过的数
- 使用python内建asyncore编写socket client
- require/require_once/include/include_once区别
- C语言——野指针
- 汉字编码及区位码查询算法
- Unicode数据类型(与ANSI关系和相互转化)
- C语言——关于指针传递指针
- 24小时值守F&Q
- 关于bootstrap".container"容器默认的before与after样式效果作用
- 2016年 天朝非科学上网 Android 源代码快速下载新选择