gmyth-stream/server/plugins/comm/tcp.py
branchtrunk
changeset 486 56b98fd15019
child 499 9900800a8dd6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth-stream/server/plugins/comm/tcp.py	Tue Apr 03 19:39:23 2007 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +import lib
     1.5 +import time
     1.6 +import socket
     1.7 +
     1.8 +class Server:
     1.9 +
    1.10 +    def __init__(self, config):
    1.11 +        self.host = ''
    1.12 +        self.port = int(config.get("Comm", "port"))
    1.13 +        self.finish = 0
    1.14 +
    1.15 +        self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    1.16 +        self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    1.17 +        self.tcp.bind( (self.host, self.port) )
    1.18 +        self.tcp.listen(1)
    1.19 +
    1.20 +    def getMsg(self, size):
    1.21 +        return self.con.recv(size)
    1.22 +
    1.23 +    def sendMsg(self, msg):
    1.24 +        self.con.send(msg + "\n")
    1.25 +
    1.26 +    def Ack(self, command):
    1.27 +        msg = "[%s] Command %s received" % (lib.now(), command)
    1.28 +        self.sendMsg(msg)
    1.29 +
    1.30 +    def getRequest(self):
    1.31 +        self.con, self.client = self.tcp.accept()
    1.32 +        print "[%s] Received request from ip=%s" % (lib.now(), self.client )
    1.33 +        return (self.con, self.client)
    1.34 +
    1.35 +    def disconnect_client(self, connection):
    1.36 +        connection.close()
    1.37 +
    1.38 +    def stop(self):
    1.39 +        self.tcp.close()