PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/docs/source/guides/server.py

https://bitbucket.org/prologic/circuits/
Python | 26 lines | 16 code | 9 blank | 1 comment | 4 complexity | 9f6eae5bf6a5c87833ff63dba4d46ecc MD5 | raw file
 1#!/usr/bin/env python
 2
 3from circuits import Component
 4from circuits.net.sockets import TCPServer, Write
 5
 6class Server(Component):
 7
 8    def __init__(self, host, port=8000):
 9        super(Server, self).__init__()
10
11        self._clients = []
12
13        TCPServer((host, port)).register(self)
14
15    def connect(self, sock, host, port):
16        self._clients.append(sock)
17
18    def disconnect(self, sock):
19        self._clients.remove(sock)
20
21    def read(self, sock, data):
22        for client in self._clients:
23            if not client == sock:
24                self.fire(Write(client, data.strip()))
25
26Server("localhost").run()