gmyth-stream/server/plugins/comm/tcp.py
author morphbr
Wed Apr 04 23:30:44 2007 +0100 (2007-04-04)
branchtrunk
changeset 504 2b5355061b66
parent 499 9900800a8dd6
child 511 16312d0021cb
permissions -rw-r--r--
[svn r509] - GMyth-Streamer:
* default port changed to 50000
* increase port used for streaming when SETUP
* changed SETUP protocol
* switch command CLOSE to QUIT
     1 import lib
     2 import time
     3 import socket
     4 
     5 class Server(object):
     6 
     7     def __init__(self, config):
     8         self.host = ''
     9         self.port = int(config.get("Comm", "port"))
    10         self.finish = 0
    11 
    12         self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    13         self.tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    14         self.tcp.bind( (self.host, self.port) )
    15         self.tcp.listen(1)
    16 
    17     def getMsg(self, size):
    18         return self.con.recv(size)
    19 
    20     def sendMsg(self, msg):
    21         self.con.send(msg + "\n")
    22 
    23     def Ack(self, command):
    24         msg = "[%s] Command %s received" % (lib.now(), command)
    25         self.sendMsg(msg)
    26 
    27     def getRequest(self):
    28         self.con, self.client = self.tcp.accept()
    29         print "[%s] Received request from ip=%s" % (lib.now(), self.client )
    30         return (self.con, self.client, self.port)
    31 
    32     def disconnect_client(self, connection):
    33         connection.close()
    34 
    35     def stop(self):
    36         self.tcp.close()