gmyth-stream/plugins/comm/tcp.py
author renatofilho
Tue Mar 27 15:36:22 2007 +0100 (2007-03-27)
branchtrunk
changeset 456 96a51561bed6
child 466 a7aba7d166fb
permissions -rw-r--r--
[svn r461] code rewrite
     1  '''
     2  # GMyth-Stream
     3  #
     4  # @file main.py
     5  #
     6  # @brief <p> Plugin for GMyth-Stream
     7  #
     8  # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
     9  # @author Artur Duque de Souza <artur.souza@indt.org.br>
    10  #
    11  #
    12  # This program is free software; you can redistribute it and/or modify
    13  # it under the terms of the GNU Lesser General Public License as published by
    14  # the Free Software Foundation; either version 2 of the License, or
    15  # (at your option) any later version.
    16  #
    17  # This program is distributed in the hope that it will be useful,
    18  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  # GNU General Public License for more details.
    21  #
    22  # You should have received a copy of the GNU Lesser General Public License
    23  # along with this program; if not, write to the Free Software
    24  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    25  #
    26  '''
    27 
    28 import time
    29 import socket
    30 
    31 class Server:
    32 
    33     def __init__(self, config):
    34         self.host = ''
    35         self.port = int(config.get("Comm", "port"))
    36         self.finish = 0
    37 
    38         self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    39         self.tcp.bind( (self.host, self.port) )
    40         self.tcp.listen(1)
    41 
    42     def now(self):
    43         return time.strftime("%Y-%m-%d %H:%M:%S");
    44 
    45     def getMsg(self, size):
    46         con = self.data[0]
    47         return con.recv(size)
    48 
    49     def getRequest(self):
    50         self.data = self.tcp.accept()
    51         print "[%s] Received request from ip=%s" % (self.now(), self.data[1] )
    52         return self.data
    53 
    54     def disconnect_client(self, connection):
    55         connection.close()
    56 
    57     def stop(self):
    58         self.tcp.close()