Example #1
0
    def setUp(self):
        self.server = create_server('0.0.0.0', 1239, 5)
        self.server.add_map(ACCEPT, self.handle_accept)

        self.client = create_client('0.0.0.0', 1239)
        self.client.add_map(LOAD, self.handle_load)
        self.sent = b''
        self.ssock = None
Example #2
0
    def setUp(self):
        self.server = create_server('0.0.0.0', 1238, 5)
        self.server.add_map(ACCEPT, self.handle_accept)

        self.client = create_client('0.0.0.0', 1238)
        self.client.add_map(CONNECT, self.handle_connect)
        self.sent = b''
        self.ssock = None
Example #3
0
    def setUp(self):
        self.server = create_server('0.0.0.0', 1235, 5)

        self.client = SuperSocket()
        self.client.connect_ex(('0.0.0.0', 1235))

        Client(self.client)
        self.client.add_map(CONNECT, self.handle_connect)
        self.server.add_map(ACCEPT, self.handle_accept)
Example #4
0
    def setUp(self):
        self.server = create_server('0.0.0.0', 1236, 5)

        self.client = create_client('0.0.0.0', 1236)
        self.client.add_map(CONNECT, self.handle_connect)
Example #5
0
    def setUp(self):
        self.server = create_server('0.0.0.0', 1241, 5)
        self.server.add_map(ACCEPT, self.handle_accept)

        self.client = create_client('0.0.0.0', 1241)
        self.client.add_map(CONNECT, self.handle_connect)
Example #6
0
    def setUp(self):
        self.server = create_server('0.0.0.0', 1237, 5)
        self.server.add_map(ACCEPT, self.handle_accept)

        self.client = create_client('0.0.0.0', 1237)
Example #7
0
from untwisted.server import create_server
from untwisted.event import ACCEPT, LOAD
from untwisted import core


class EchoServer:
    def __init__(self, server):
        server.add_map(
            ACCEPT, lambda server, con: con.add_map(
                LOAD, lambda con, data: con.dump(data)))


if __name__ == '__main__':
    EchoServer(create_server('0.0.0.0', 1234, 5))
    core.gear.mainloop()
Example #8
0
from untwisted.tools import coroutine
from untwisted import core


class ChatServer:
    def __init__(self, server):
        server.add_map(ACCEPT, self.handle_accept)
        self.pool = []

    @coroutine
    def handle_accept(self, server, client):
        Terminator(client, delim=b'\r\n')
        client.add_map(CLOSE, lambda client, err: self.pool.remove(client))

        client.dump(b'Type a nick.\r\nNick:')
        client.nick, = yield client, Terminator.FOUND

        client.add_map(Terminator.FOUND, self.echo_msg)
        self.pool.append(client)

    def echo_msg(self, client, data):
        for ind in self.pool:
            if not ind is client:
                ind.dump(b'%s:%s\r\n' % (client.nick, data))


if __name__ == '__main__':
    server = create_server('', 1234, 5)
    ChatServer(server)
    core.gear.mainloop()