python how to serve multiple tcp clients with input from single udp port?
Question: I have a python TCP server that listens for incoming data requests. As soon as
someone connects to it, the server starts serving data to that client. The
data it serves comes in via UDP on some port.

The question is, how can I serve the same data coming in from a UDP port to
potentially multiple tcp clients?

Some background info: 1\. a thread is created to listen for incoming UDP data.
2\. A new thread is created every time a new TCP clients connects.

I looked at the python Queue package, but it seems this is point-to-point and
limiting for my objective.

Any ideas?


Answer: You could hide the point-to-point connections in a class, for example:

    
    
    from multiprocessing import Queue
    from threading import Lock
    
    class BroadcastChannel():
      def __init__(self):
        self._queues = []
        self.lock = Lock()
      def send(self, item):
        self.lock.acquire()
        for q in self._queues:
          q.put(item)
        self.lock.release()
      def fork(self):
        q = Queue()
        self.lock.acquire()
        self._queues.append(q)
        self.lock.release()
        return q
    

