diff -r 000000000000 -r 63d9475228ac gmyth-stream/server/plugins/comm/tcp.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/server/plugins/comm/tcp.py Wed Apr 04 00:10:15 2007 +0100 @@ -0,0 +1,36 @@ +import lib +import time +import socket + +class Server: + + def __init__(self, config): + self.host = '' + self.port = int(config.get("Comm", "port")) + self.finish = 0 + + self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.tcp.bind( (self.host, self.port) ) + self.tcp.listen(1) + + def getMsg(self, size): + return self.con.recv(size) + + def sendMsg(self, msg): + self.con.send(msg + "\n") + + def Ack(self, command): + msg = "[%s] Command %s received" % (lib.now(), command) + self.sendMsg(msg) + + def getRequest(self): + self.con, self.client = self.tcp.accept() + print "[%s] Received request from ip=%s" % (lib.now(), self.client ) + return (self.con, self.client) + + def disconnect_client(self, connection): + connection.close() + + def stop(self): + self.tcp.close()