Exemplo n.º 1
0
def main():
    conf = {"address": ("127.0.0.1", 5000), "debug": True, "num_workers": 3}
    spec = (
        HttpWorker,
        30,
        "send_file",
        {},
        "worker",
    )

    arbiter = TcpArbiter(conf, spec)
    arbiter.run()
Exemplo n.º 2
0
from http_parser.http import HttpStream
from http_parser.reader import SocketReader


class MyTcpWorker(TcpSyncWorker):
    def handle(self, sock, addr):
        p = HttpStream(SocketReader(sock))

        path = p.path()
        data = "hello world"
        sock.send("".join([
            "HTTP/1.1 200 OK\r\n", "Content-Type: text/html\r\n",
            "Content-Length:" + str(len(data)) + "\r\n",
            "Connection: close\r\n\r\n", data
        ]))


if __name__ == '__main__':
    conf = {"num_workers": 3}
    spec = (
        MyTcpWorker,
        30,
        "worker",
        {},
        "worker",
    )

    arbiter = TcpArbiter(conf, spec)

    arbiter.run()