gmyth-stream/plugins/comm/tcp.py
author morphbr
Fri Mar 30 04:12:52 2007 +0100 (2007-03-30)
branchtrunk
changeset 470 57833200a415
parent 466 a7aba7d166fb
child 471 2eef40885322
permissions -rw-r--r--
[svn r475] Regarding GMyth-Stream:

- Bug fixes
- Better error handling
- Return messages to client
- Created a lib.py with common functions
- Improved API of comm plugins
     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.bind( (self.host, self.port) )
    14         self.tcp.listen(1)
    15 
    16     def getMsg(self, size):
    17         return self.con.recv(size)
    18 
    19     def sendMsg(self, msg):
    20         self.con.send(msg)
    21 
    22     def Ack(self, command):
    23         msg = "[%s] Command %s received" % (lib.now(), command)
    24         self.sendMsg(msg + "\n")
    25 
    26     def getRequest(self):
    27         self.con, self.client = self.tcp.accept()
    28         print "[%s] Received request from ip=%s" % (lib.now(), self.client )
    29         return (self.con, self.client)
    30 
    31     def disconnect_client(self, connection):
    32         connection.close()
    33 
    34     def stop(self):
    35         self.tcp.close()