Advertisement

SDL Net - Receiving and sending on same TCP connection ?

Started by October 12, 2013 11:44 AM
2 comments, last by ElCommunist 11 years, 4 months ago

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

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

Advertisement

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.

enum Bool { True, False, FileNotFound };

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.

This topic is closed to new replies.

Advertisement