gmyth-stream/server/plugins/comm/tcp.py
author morphbr
Wed Apr 04 00:10:15 2007 +0100 (2007-04-04)
branchtrunk
changeset 492 63d9475228ac
child 499 9900800a8dd6
permissions -rw-r--r--
[svn r497] - Updated gmyth-streamer mencoder, xmlrpc and client_ffmpeg
     1 import lib
     2 import time
     3 import socket
     4 
     5 class Server:
     6 
     7     def __init__(self, config):
     8         self.host = ''
     9         self.port = int(config.get("Comm", "port"))
    10         self.finish = 0
    11 
    12         self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    13         self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    14         self.tcp.bind( (self.host, self.port) )
    15         self.tcp.listen(1)
    16 
    17     def getMsg(self, size):
    18         return self.con.recv(size)
    19 
    20     def sendMsg(self, msg):
    21         self.con.send(msg + "\n")
    22 
    23     def Ack(self, command):
    24         msg = "[%s] Command %s received" % (lib.now(), command)
    25         self.sendMsg(msg)
    26 
    27     def getRequest(self):
    28         self.con, self.client = self.tcp.accept()
    29         print "[%s] Received request from ip=%s" % (lib.now(), self.client )
    30         return (self.con, self.client)
    31 
    32     def disconnect_client(self, connection):
    33         connection.close()
    34 
    35     def stop(self):
    36         self.tcp.close()