Jump to content
  • Advertisement
Sign in to follow this  
tufflax

[Python] 2 threads send and recv on same blocking socket

This topic is 3942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey! I have a question about sockets in Python (and in general I guess): If I have a client socket that is blocking, waiting for something to come in (a blocking recv() call). Can another thread use the same socket to send something (and vice versa)? I tried with a little sample program and it worked, but I figured it might not be such a good idea in general, or? What's the deal? [Edited by - tufflax on January 7, 2008 3:30:18 AM]

Share this post


Link to post
Share on other sites
Advertisement
That sounds like it could give you a lot of headaches. Threading can get quite dirty already, and a socket doesn't really support reading from it and writing to it simultanously as far as I know.

You should probably take a look at asyncore/asynchat in the python standard library for ways to do this without using threading. Or, alternative, Twisted (twistedmatrix.com).

Share this post


Link to post
Share on other sites
Sockets in general should be thread-safe, although you need to confirm it for your particular implementation.

But as said, Python has Twisted, which should be your choice for networking, and should also solve the problem with blocking.

Share this post


Link to post
Share on other sites
Thanks for your answers. Ok, I'll look into twisted and asyncore...

[Edited by - tufflax on January 7, 2008 2:46:45 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!