morphbr@470: import lib morphbr@453: import time morphbr@453: import socket morphbr@453: morphbr@453: class Server: morphbr@453: morphbr@453: def __init__(self, config): morphbr@453: self.host = '' morphbr@453: self.port = int(config.get("Comm", "port")) morphbr@453: self.finish = 0 morphbr@453: morphbr@453: self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) morphbr@471: self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) morphbr@453: self.tcp.bind( (self.host, self.port) ) morphbr@453: self.tcp.listen(1) morphbr@453: morphbr@470: def getMsg(self, size): morphbr@470: return self.con.recv(size) morphbr@453: morphbr@470: def sendMsg(self, msg): morphbr@470: self.con.send(msg) morphbr@470: morphbr@470: def Ack(self, command): morphbr@470: msg = "[%s] Command %s received" % (lib.now(), command) morphbr@470: self.sendMsg(msg + "\n") morphbr@453: morphbr@453: def getRequest(self): morphbr@470: self.con, self.client = self.tcp.accept() morphbr@470: print "[%s] Received request from ip=%s" % (lib.now(), self.client ) morphbr@470: return (self.con, self.client) morphbr@453: morphbr@453: def disconnect_client(self, connection): morphbr@453: connection.close() morphbr@453: morphbr@453: def stop(self): morphbr@453: self.tcp.close()