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