views:

133

answers:

1

I have written a little streaming mp3 server in python. So far all it does is accept a ServerSocket connection, and begin streaming all mp3 data in its queue to the request using socket.send(). I have implemented this to chunk in stream icy metadata, so the name of the playing song shows up in the client.

I would like to add playlist management to the server, so that I can manipulate the playlist of the running server. I have a vague idea that xmlrpclib would be suited to doing this, but I'm confused about two things:

  1. Whether it's possible/advisable to integrate ICY and XMLRPC on a single server and a single port.

  2. How to share state between the stream thread and the playlist, and manipulation thereof via xmlrpc.

A: 

Your initial attempt might be easier if you use two separate ports, each with its own server running in a separate thread. However, managing synchronization between the threads might be an annoying task in the long run.

ICY and HTTP are very similar, and if you've already implemented ICY on top of SocketServer, you could probably extend BaseHTTPServer.BaseHTTPRequestHandler to respond to both ICY and HTTP requests on the same port. Take a look at the standard library code for the BaseHTTPRequestHandler.parse_request() method, and think about how to override it in a subclass for a split personality.

Also, when you want to handle multiple concurrent requests using these classes, take a look at the SocketServer mixin classes.

Forest
Will a BaseHTTPRequestHandler receive xmlrpc? I understand HTTP could be used for all of this but my question is geared toward going it with two different protocols in the same server. Yes, I need synchronization. And yes, I'm using the thread mixin
Noah
Yes, I understand your goal of two protocols on the same server. As I said, it will take some work. Note that SimpleXMLRPCServer is based on the same class hierarchy as BaseHTTPServer. My suggestion is to read the code for both, understand the shared parts and differences, and come up with your own subclasses that tie the needed functionality together.
Forest
@Forest -- I have implemented a BaseHTTPServer to handle both ICY and XML RPC. Thanks for your pointers.Any pointers for how to implement shared state for this beast?
Noah
I think you might get more responses if you ask it as a new question. Congratulations on your progress!
Forest
Yeah, sorry I can't accept your answer twice.
Noah