File: simple_server.py

package info (click to toggle)
circuits 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,384 kB
  • ctags: 3,037
  • sloc: python: 14,416; makefile: 146; sh: 61
file content (26 lines) | stat: -rw-r--r-- 619 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python

from circuits import Component
from circuits.net.sockets import TCPServer, Write

class Server(Component):

    def __init__(self, host, port=8000):
        super(Server, self).__init__()

        self._clients = []

        TCPServer((host, port)).register(self)

    def connect(self, sock, host, port):
        self._clients.append(sock)

    def disconnect(self, sock):
        self._clients.remove(sock)

    def read(self, sock, data):
        for client in self._clients:
            if not client == sock:
                self.fire(Write(client, data.strip()))

Server("localhost").run()