예제 #1
0
from twisted.internet import protocol, reactor
from time import ctime

PORT = 10001


class TSServerProtocol(protocol.Protocol):
    def connectionMade(self):
        client = self.client = self.transport.getPeer().host
        print(client)
        print('等待连接,来自:', client)

    def dataReceived(self, data):
        data = data.decode()
        print('收到的内容:', data)
        self.transport.write(('[%s] %s' % (ctime(), data)).encode())


factory = protocol.Factory()
factory.protocol = TSServerProtocol
print('等待连接:')
reactor.listenTCP(PORT, factory)
reactor.run()
예제 #2
0
def start():
    factory = protocol.Factory()
    factory.protocol = HubFeed
    reactor.listenTCP(hubPort, factory)
    print('hub simulator ready on port', hubPort)
    reactor.run()
예제 #3
0
from twisted.internet import protocol, reactor
from time import ctime

PORT = 21567

dash = '-' * 50


class TSServProtocol(protocol.Protocol):
    def connectionMade(self):
        clnt = self.clnt = self.transport.getPeer().host
        port = self.port = self.transport.getPeer().port
        print '...connection from : [%s] %s ' % (clnt, port)

    def dataReceived(self, data):
        print '...receive data : ', data
        self.transport.write('[%s] %s' % (ctime(), data))


try:
    factory = protocol.Factory()  #创建一个工厂,每次有连接进来时,就会产生一个protocal对象。来监听请求。
    factory.protocol = TSServProtocol  #请求进来是,创建一个TSSserProtocol进行处理
    print 'waiting for connection...'
    print dash

    reactor.listenTCP(PORT, factory)
    reactor.run()
except (EOFError, KeyboardInterrupt) as e:
    print 'Error:', e.message
    reactor.stop()
예제 #4
0
 def test_socketsLeftOpen(self):
     f = protocol.Factory()
     f.protocol = protocol.Protocol
     reactor.listenTCP(0, f)
예제 #5
0
파일: server.py 프로젝트: uponup/swift-2
def main():
    factory = protocol.Factory()
    factory.clients = []
    factory.protocol = CameraProtocol
    reactor.listenTCP(8800, factory)
    reactor.run()
예제 #6
0
파일: pool.py 프로젝트: snauman817/nav
def initialize_worker():
    handler = JobHandler()
    factory = protocol.Factory()
    factory.protocol = lambda: ProcessAMP(is_worker=True, locator=handler)
    StandardIOEndpoint(reactor).listen(factory)
    return handler