gmyth-stream/server/main.py
branchtrunk
changeset 490 b15d16fb4039
child 497 08a2d7d67ae5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth-stream/server/main.py	Tue Apr 03 20:12:01 2007 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +#!/usr/bin/python
     1.5 +
     1.6 +import os
     1.7 +import lib
     1.8 +import sys
     1.9 +import ConfigParser
    1.10 +
    1.11 +config = ConfigParser.ConfigParser()
    1.12 +config.read("stream.conf")
    1.13 +
    1.14 +media_plugin = config.get("Media", "engine")
    1.15 +exec("from plugins.media.%s import *" % media_plugin)
    1.16 +
    1.17 +media = Media(config)
    1.18 +
    1.19 +comm_plugin = config.get("Comm", "engine")
    1.20 +exec("from plugins.comm.%s import *" % comm_plugin)
    1.21 +
    1.22 +# Start Our Server:
    1.23 +server = Server(config)
    1.24 +
    1.25 +lib.log("Starting GMyth-Stream server")
    1.26 +
    1.27 +while (server.finish == 0):
    1.28 +    con, client = server.getRequest()
    1.29 +
    1.30 +    while True:
    1.31 +        msg = server.getMsg(1024).strip()
    1.32 +
    1.33 +        if not msg: break
    1.34 +
    1.35 +        lib.log("Received %s from: %s" % (msg, client) )
    1.36 +
    1.37 +        if (msg == "SETUP"):
    1.38 +            setup = server.getMsg(1024).strip().split(" ")
    1.39 +            size = len(setup)
    1.40 +            options = []
    1.41 +
    1.42 +            if ( size < 10 ):
    1.43 +                server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
    1.44 +
    1.45 +            else:
    1.46 +
    1.47 +                if ( size > 10 ):
    1.48 +                    i = 10
    1.49 +                    while (i < size):
    1.50 +                        options.append(setup[i])
    1.51 +                        i += 1
    1.52 +
    1.53 +                ret = media.setup(setup[0], setup[1], setup[2], \
    1.54 +                                  setup[3], setup[4], setup[5],
    1.55 +                                  setup[6], setup[7], setup[8],
    1.56 +                                  setup[9], options)
    1.57 +
    1.58 +                if (ret == 0):
    1.59 +                    server.Ack("SETUP")
    1.60 +                else:
    1.61 +                    server.sendMsg(lib.log(ret))
    1.62 +
    1.63 +
    1.64 +        elif (msg == "PLAY"):
    1.65 +            media.play()
    1.66 +            server.Ack("PLAY")
    1.67 +
    1.68 +        elif (msg == "STOP"):
    1.69 +            media.stop()
    1.70 +            server.Ack("STOP")
    1.71 +
    1.72 +        elif (msg == "CLOSE"):
    1.73 +            server.finish = 1
    1.74 +            media.stop()
    1.75 +            server.Ack("CLOSE")
    1.76 +            break
    1.77 +
    1.78 +    lib.log("Closing connection with %s" % client[0])
    1.79 +    server.disconnect_client(con)
    1.80 +
    1.81 +server.stop()
    1.82 +del(server)
    1.83 +lib.log("Server stopped. Closing...")
    1.84 +