gmyth-stream/server/main.py
author renatofilho
Wed Apr 04 21:53:33 2007 +0100 (2007-04-04)
branchtrunk
changeset 502 aa932d8bf85b
parent 497 08a2d7d67ae5
child 504 2b5355061b66
permissions -rwxr-xr-x
[svn r507]
     1 #!/usr/bin/python
     2 
     3 import os
     4 import lib
     5 import sys
     6 import ConfigParser
     7 
     8 config = ConfigParser.ConfigParser()
     9 config.read("stream.conf")
    10 
    11 media_plugin = config.get("Media", "engine")
    12 exec("from plugins.media.%s import *" % media_plugin)
    13 
    14 media = Media(config)
    15 
    16 comm_plugin = config.get("Comm", "engine")
    17 exec("from plugins.comm.%s import *" % comm_plugin)
    18 
    19 # Start Our Server:
    20 server = Server(config)
    21 
    22 lib.log("Starting GMyth-Stream server")
    23 
    24 while (server.finish == 0):
    25     con, client = server.getRequest()
    26 
    27     while True:
    28         msg = server.getMsg(1024).strip()
    29 
    30         if not msg: break
    31 
    32         lib.log("Received %s from: %s" % (msg, client) )
    33 
    34         if msg == "SETUP":
    35             setup = server.getMsg(1024).strip().split(" ")
    36             size = len(setup)
    37             options = []
    38 
    39             if size < 10:
    40                 server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
    41 
    42             else:
    43 
    44                 if size > 10:
    45                     i = 10
    46                     while (i < size):
    47                         options.append(setup[i])
    48                         i += 1
    49 
    50                 ret = media.setup(setup[0], setup[1], setup[2], \
    51                                   setup[3], setup[4], setup[5],
    52                                   setup[6], setup[7], setup[8],
    53                                   setup[9], options)
    54 
    55                 if ret == 0:
    56                     server.Ack("SETUP")
    57                 else:
    58                     server.sendMsg(lib.log(ret))
    59 
    60 
    61         elif msg == "PLAY":
    62             media.play()
    63             server.Ack("PLAY")
    64 
    65         elif msg == "STOP":
    66             media.stop()
    67             server.Ack("STOP")
    68 
    69         elif msg == "CLOSE":
    70             server.finish = 1
    71             media.stop()
    72             server.Ack("CLOSE")
    73             break
    74 
    75     lib.log("Closing connection with %s" % client[0])
    76     server.disconnect_client(con)
    77 
    78 server.stop()
    79 del(server)
    80 lib.log("Server stopped. Closing...")
    81