gmyth-stream/plugins/comm/tcp.py
author renatofilho
Tue Apr 03 16:42:04 2007 +0100 (2007-04-03)
branchtrunk
changeset 484 27e83a8f68d7
parent 471 2eef40885322
permissions -rw-r--r--
[svn r489] moved server implementation to new dir
     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()