【脚本编程系列】关于Python网络通讯asyncore,你需要知道的事
来源:互联网 发布:怎样快速养淘宝小号 编辑:程序博客网 时间:2024/06/06 18:20
如何使用asyncore
# -*- coding:utf-8 -*-import asyncore, socketclass HttpClient(asyncore.dispatcher): def __init__(self, host, path): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((host, 80)) self.buffer = "GET %s HTTP/1.0 \r\n\r\n" %path def handle_connect(self): pass def handle_close(self): self.close() def handle_read(self): print self.recv(1024) def handle_write(self): sent = self.send(self.buffer) self.buffer = self.buffer[sent:] def writable(self): return (len(self.buffer)>0)if __name__ == "__main__": c = HttpClient("www.python.org","/") asyncore.loop()
HTTP/1.1 500 Domain Not FoundServer: VarnishRetry-After: 0content-type: text/htmlCache-Control: private, no-cacheconnection: keep-aliveContent-Length: 179Accept-Ranges: bytesDate: Tue, 13 Jun 2017 08:11:23 GMTVia: 1.1 varnishConnection: close<html><head><title>Fastly error: unknown domain </title></head><body>Fastly error: unknown domain: . Please check that this domain has been added to a service.</body></html>
什么是asyncore
asyncore模块实现异步通信方式,提供了用来构建异步通信方式的客户端和服务器端的基础架构。
尤其适合聊天类的服务器端和协议的实现。
其运行过程是创建一个或多个网络信道;当信道创建后,通过轮询方式来激活网络信道的服务,直到最后一个网络信道关闭。
阅读全文
0 0
- 【脚本编程系列】关于Python网络通讯asyncore,你需要知道的事
- 【脚本语言系列】关于Python网络通讯Twisted网络框架,你需要知道的事
- 【脚本语言系列】关于Python网络通讯socket,你需要知道的事
- 【脚本语言系列】关于Python多线程编程StacklessPython,你需要知道的事
- 【脚本语言系列】关于Python多线程编程Threading, 你需要知道的事
- 【脚本语言系列】关于Python网络编程socket,你需要知道的事
- 【脚本语言系列】关于Python基础知识面向对象编程,你需要知道的事
- 【脚本语言系列】关于Python数据库编程ODBC,你需要知道的事
- 【脚本语言系列】关于Python系统管理,你需要知道的事
- 【脚本语言系列】关于Python容器,你需要知道的事
- 【脚本语言系列】关于Python调试报错,你需要知道的事
- 【脚本语言系列】关于Python开发环境搭建,你需要知道的事
- 【脚本语言系列】关于Python数值计算NumPy, 你需要知道的事
- 【脚本语言系列】关于Python测试工具lettuce, 你需要知道的事
- 【脚本语言系列】关于Python测试工具mock, 你需要知道的事
- 【脚本语言系列】关于Python测试工具unittest, 你需要知道的事
- 【脚本语言系列】关于Python测试工具docstrings, 你需要知道的事
- 【脚本语言系列】关于Python测试工具Pyflakes, 你需要知道的事
- Hbase优化
- std::max、std::min error C2589: “(”:“::”右边的非法标记,error C2059: 语法错误:“::”
- java项目打jar包的两种情况
- Android最佳实践 —— 详细谈谈如何减小APK体积
- mysql---使用函数处理数据
- 【脚本编程系列】关于Python网络通讯asyncore,你需要知道的事
- Docker install for rhel7
- 两周学会Python 第01天(下午)
- linux命令ASCII码与字符互转
- AndroidStudio 运行出现"Session 'app' : Error Launching activity"
- 前端项目引入苹方字体
- 柯西定理与留数定理的应用总结
- 约瑟夫问题(约瑟夫环) java
- Jenkins+maven+jmeter接口可持续集成自动化测试