Sign in to follow this  
ElCommunist

SDL Net - Receiving and sending on same TCP connection ?

Recommended Posts

ElCommunist    107

Hello everyone, and thanks for your valuable time smile.png

 

I am working on the networking part of a game, using SDL_Net as Networking library.

I tried the tutorial about SDL_Net TCP basics, and everything worked fine (server listening, client sending)

 

But now, I don't really know how to design the communication in both directions :

I would like to create one thread listening via the server TCP socket, and another thread sending via the same socket, at the same time (so this is the same TCP connection used for both sending and receiving, potentially simultaneously))

-> Is it safe ? performant ?

-> Or do I need to create one TCP connection for sending messages on one thread, and another TCP connection for listening on another thread ?

 

I know that some TCP connection are duplex which enable what I want, but I don't know about SDL Net...

 

Again, thanks for your help smile.png

Edited by ElCommunist

Share this post


Link to post
Share on other sites
3TATUK2    714

I don't think you should really have to worry about splitting send/receive into separate threads. Just do them "procedurally"/"immediately" ... internally they will get queued in the appropriate manner to be handled

Share this post


Link to post
Share on other sites
hplus0603    11348

WinSock 1.x didn't support simultaneous send/receive on sockets. WinSock 2.2, which is what everyone should have been using for the last 20 years or so, does support that. Linux has always supported that AFAIK.

Note that "TCP connection" and "socket" are slightly different concepts -- you're really asking about sockets here.

Share this post


Link to post
Share on other sites
ElCommunist    107

Thanks for your answers :-)

 

Finally I will go with 3STATUK2 idea (synchronous way) and look at game loop performance. I will try later to go asynchronously and compare the two.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this