gmyth-stream/plugins/comm/tcp.py
author renatofilho
Wed Mar 28 21:26:42 2007 +0100 (2007-03-28)
branchtrunk
changeset 468 f4c6061f6f39
parent 453 a806d8ad0ff0
child 470 57833200a415
permissions -rw-r--r--
[svn r473] memory leek fix
morphbr@453
     1
import time
morphbr@453
     2
import socket
morphbr@453
     3
morphbr@453
     4
class Server:
morphbr@453
     5
morphbr@453
     6
    def __init__(self, config):
morphbr@453
     7
        self.host = ''
morphbr@453
     8
        self.port = int(config.get("Comm", "port"))
morphbr@453
     9
        self.finish = 0
morphbr@453
    10
morphbr@453
    11
        self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
morphbr@453
    12
        self.tcp.bind( (self.host, self.port) )
morphbr@453
    13
        self.tcp.listen(1)
morphbr@453
    14
morphbr@453
    15
    def now(self):
morphbr@453
    16
        return time.strftime("%Y-%m-%d %H:%M:%S");
morphbr@453
    17
morphbr@453
    18
    def getMsg(self, size):
morphbr@453
    19
        con = self.data[0]
morphbr@453
    20
        return con.recv(size)
morphbr@453
    21
morphbr@453
    22
    def getRequest(self):
morphbr@453
    23
        self.data = self.tcp.accept()
morphbr@453
    24
        print "[%s] Received request from ip=%s" % (self.now(), self.data[1] )
morphbr@453
    25
        return self.data
morphbr@453
    26
morphbr@453
    27
    def disconnect_client(self, connection):
morphbr@453
    28
        connection.close()
morphbr@453
    29
morphbr@453
    30
    def stop(self):
morphbr@453
    31
        self.tcp.close()