1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gmyth-stream/plugins/comm/tcp.py Tue Mar 27 21:42:35 2007 +0100
1.3 @@ -0,0 +1,58 @@
1.4 + '''
1.5 + # GMyth-Stream
1.6 + #
1.7 + # @file main.py
1.8 + #
1.9 + # @brief <p> Plugin for GMyth-Stream
1.10 + #
1.11 + # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
1.12 + # @author Artur Duque de Souza <artur.souza@indt.org.br>
1.13 + #
1.14 + #
1.15 + # This program is free software; you can redistribute it and/or modify
1.16 + # it under the terms of the GNU Lesser General Public License as published by
1.17 + # the Free Software Foundation; either version 2 of the License, or
1.18 + # (at your option) any later version.
1.19 + #
1.20 + # This program is distributed in the hope that it will be useful,
1.21 + # but WITHOUT ANY WARRANTY; without even the implied warranty of
1.22 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.23 + # GNU General Public License for more details.
1.24 + #
1.25 + # You should have received a copy of the GNU Lesser General Public License
1.26 + # along with this program; if not, write to the Free Software
1.27 + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.28 + #
1.29 + '''
1.30 +
1.31 +import time
1.32 +import socket
1.33 +
1.34 +class Server:
1.35 +
1.36 + def __init__(self, config):
1.37 + self.host = ''
1.38 + self.port = int(config.get("Comm", "port"))
1.39 + self.finish = 0
1.40 +
1.41 + self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1.42 + self.tcp.bind( (self.host, self.port) )
1.43 + self.tcp.listen(1)
1.44 +
1.45 + def now(self):
1.46 + return time.strftime("%Y-%m-%d %H:%M:%S");
1.47 +
1.48 + def getMsg(self, size):
1.49 + con = self.data[0]
1.50 + return con.recv(size)
1.51 +
1.52 + def getRequest(self):
1.53 + self.data = self.tcp.accept()
1.54 + print "[%s] Received request from ip=%s" % (self.now(), self.data[1] )
1.55 + return self.data
1.56 +
1.57 + def disconnect_client(self, connection):
1.58 + connection.close()
1.59 +
1.60 + def stop(self):
1.61 + self.tcp.close()