SFML community forums
Help => Network => Topic started by: Walker on January 29, 2011, 05:22:18 pm
-
Hey, probably some pretty simple newbie network questions here. Using SFML 2 by the way.
I'm wondering if sockets are intended to be reused - should I create my socket/listener and use it to receive data throughtout the running of my program or should I create a socket everytime I receive data? Does it matter?
Also, what exactly changes when you SetBlocking(false)? Does it return instantly and you have to keep calling Receive() until there is some incoming packets?
Bear in mind this is for a small real time multiplayer game.
Any pointers would be appreciated.
Cheers :)
-
Why would you create a socket every time you recveive data? And how would you know that there is data to receive if the socket is not created, by the way? ;)
Also, what exactly changes when you SetBlocking(false)? Does it return instantly and you have to keep calling Receive() until there is some incoming packets?
Absolutely.
-
Not sure, just checking! :oops:
Thanks for the reply!
So I think this will be the stupidest question so far but when data gets sent, will it be available to receive until I read it, until the sending socket is closed, only while the listener is listening or something else?
I guess what I want to know is that if I shoot off some packet, and I'm calling Receive() at X rate on the target computer, is it a certainty that it gets picked up (provided there are no issues on its journey)?
-
So I think this will be the stupidest question so far but when data gets sent, will it be available to receive until I read it, until the sending socket is closed, only while the listener is listening or something else?
As far as I know, it is available until you read it, even if the sending socket is closed. The listener has nothing to do with that, once a connection is established, its job is done.
I guess what I want to know is that if I shoot off some packet, and I'm calling Receive() at X rate on the target computer, is it a certainty that it gets picked up (provided there are no issues on its journey)?
Yes. Incoming messages are buffered until you read them. The only possible issue that may happen, is that you have too many messages and too few calls to Receive: in this case the buffer will overflow and you will loose messages.
-
Thanks for the speedy replies, Laurent! This clears a lot of confusion up :D