简体   繁体   English

带有RPC的python流式TCP服务器

[英]python streaming TCP server with RPC

I have written a little streaming mp3 server in python. 我已经用python编写了一个流式mp3服务器。 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(). 到目前为止,它所做的只是接受ServerSocket连接,并开始使用socket.send()将其队列中的所有mp3数据流传输到请求。 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: 我有一个模糊的想法,即xmlrpclib将适合执行此操作,但是我对两件事感到困惑:

  1. Whether it's possible/advisable to integrate ICY and XMLRPC on a single server and a single port. 是否可以/建议在单个服务器和单个端口上集成ICY和XMLRPC。

  2. How to share state between the stream thread and the playlist, and manipulation thereof via xmlrpc. 如何在流线程和播放列表之间共享状态,以及如何通过xmlrpc对其进行操作。

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. ICY和HTTP非常相似,如果您已经在SocketServer上实现了ICY,则可以扩展BaseHTTPServer.BaseHTTPRequestHandler以在同一端口上响应ICY和HTTP请求。 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. 看一下BaseHTTPRequestHandler.parse_request()方法的标准库代码,并考虑如何在子类中重写它以实现个性化。

Also, when you want to handle multiple concurrent requests using these classes, take a look at the SocketServer mixin classes . 另外,当您想使用这些类处理多个并发请求时,请查看SocketServer mixin类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM