greecket - a python not block socket module base the greenlet and thread - Google Project Hosting
11155 단어 project
greecket, greenlet 과 threading 을 기반 으로 하 는 python 비 차단 모드 socket 모듈.
the greecket uer mail list:
web: http://groups.google.com/group/greecket
mail:[email protected]
example
greecket_test.py
#!/usr/bin/env python
#!coding=utf-8
import greecket
import sys
def onConnecting(evt):
print 'connecting',evt.AsList
def onConnected(evt):
print 'connected',evt.AsList
evt.Data.send('dfsdfsfsfff')
pass
def onReceive(event):
print 'data receive:',event.AsList
def onError(evt):
print 'error:',evt.AsList
print evt.Data.args[1]
pass
def onClose(evt):
print 'close',evt.AsList
def runasserver(address):#host='localhost',port=5423):
factory=greecket.Factory(address)
print 'server',factory
factory.bind(greecket.GREE_CONNECTING,onConnecting)
factory.bind(greecket.GREE_CONNECTIONMADE,onConnected)
factory.bind(greecket.GREE_DATARECEIVED,onReceive)
factory.bind(greecket.GREE_CONNECTIONLOST,onClose)
factory.bind(greecket.GREE_ERROR,onError)
factory.listen()
return factory
def client(address):
factory=greecket.Factory(address)
print 'client',factory
factory.bind(greecket.GREE_CONNECTING,onConnecting)
factory.bind(greecket.GREE_CONNECTIONMADE,onConnected)
factory.bind(greecket.GREE_DATARECEIVED,onReceive)
factory.bind(greecket.GREE_CONNECTIONLOST,onClose)
factory.bind(greecket.GREE_ERROR,onError)
factory.bind(greecket.GREE_DATARECEIVED,onReceive)
factory.bind(greecket.GREE_ERROR,onError)
factory.connect()
return factory
if __name__=='__main__':
print sys.argv
if len(sys.argv)>2:
d=tuple((sys.argv[-2],int(sys.argv[-1])))
else:
d=('localhost',5423)
if 'server' in sys.argv:
f=runasserver(d)
else:
f=client(d)
f.mainLoop()
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Personal analysis of the Daily project on GitHubAnalysis of other people's projects on github. Learn from him well. https://github.com/spring2613/Daily The project has ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.