0

I'm working on a really basic "image streaming" server as a school subject, and I've done most of the work but I'm still stuck on the separation between data and control related sockets:

My structure is : TCPServer (my server, used as control socket) contains a dataSocket (only used to send images and initialized within my TCPServer object, when I receive a certain query)

When I'm sending data (images) through my dataSocket, I still need to see if the client sent a PAUSE or STOP request, but if I use python's self.request.recv(1024) the server awaits a response instead of continuing to send data (which is quite logical).

What should I do to prevent this behavior ? Should I launch my recv(1024) on a separate thread and run it at each loop (and check if I get any relevant data in between two iterations) ?

2
  • 1
    I think you will have to post some code if you want an answer. Are you saying you have two separate sockets between a client and server? One socket you send/receive control messages (like pause/stop) and the other socket you send/receive data messages? You are getting your control socket by subclassing SocketServer.TCPServer and then creating the data socket within that class? In general if you handling multiple sockets you need either threads or to use something like select: docs.python.org/2/library/select.html Commented Nov 29, 2012 at 17:14
  • You got everything right. My class (subclass of TCPSocket) handles the control queries, and also contains another socket (called dataSocket) that handle the data part. Maybe I should give select() a try as I try to minimize the number of threads launched in my app. Commented Nov 30, 2012 at 17:53

1 Answer 1

1

Twisted should do the trick! It handles asynchronous sockets in Python

Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunately I can't use external (high-level) librairies as the goal of this exercise is to learn to work with low-level networking.
but you're allowed to ask on stackexchange how to do your homework
Yes, as Stackexchange is here to understand how (cool) things work. (at least that's what I'm using it for :-)).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.