def main(): loop = pyev.default_loop() signal_handler = whizzer.signal_handler(loop) factory = whizzer.ProtocolFactory() factory.protocol = EchoClientProtocol clients = [] # number of parallel clients for x in range(0, 2): clients.append(EchoClient(x, loop, factory)) signal_handler.start() loop.loop()
def main(): loop = pyev.default_loop() signal_handler = whizzer.signal_handler(loop) signal_handler.start() factory = EchoProtocolFactory() server = whizzer.TcpServer(loop, factory, "127.0.0.1", 2000, 256) stats = EchoStatistics(loop, factory) signal_handler.start() server.start() stats.start() loop.loop()
http://nichol.as/asynchronous-servers-in-python """ import sys import pyev sys.path.insert(0, '..') import whizzer class PongProtocol(whizzer.Protocol): def connection_made(self): self.transport.write( "HTTP/1.0 200 OK\r\nContent-Length: 5 \r\n\r\nPong!\r\n") self.lose_connection() loop = pyev.default_loop() sigwatcher = whizzer.signal_handler(loop) factory = whizzer.ProtocolFactory() factory.protocol = PongProtocol server = whizzer.TcpServer(loop, factory, "0.0.0.0", 8000, 500) sigwatcher.start() server.start() loop.loop()
This ping pong web server compares extremely well to everything else listed on Nicholas's website. http://nichol.as/asynchronous-servers-in-python """ import sys import pyev sys.path.insert(0, '..') import whizzer class PongProtocol(whizzer.Protocol): def connection_made(self): self.transport.write("HTTP/1.0 200 OK\r\nContent-Length: 5 \r\n\r\nPong!\r\n") self.lose_connection() loop = pyev.default_loop() sigwatcher = whizzer.signal_handler(loop) factory = whizzer.ProtocolFactory() factory.protocol = PongProtocol server = whizzer.TcpServer(loop, factory, "0.0.0.0", 8000, 500) sigwatcher.start() server.start() loop.loop()