Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Reusing sockets and non-blocking sockets  (Read 2690 times)

0 Members and 1 Guest are viewing this topic.

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Reusing sockets and non-blocking sockets
« 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 :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Reusing sockets and non-blocking sockets
« Reply #1 on: January 29, 2011, 05:42:53 pm »
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? ;)

Quote
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.
Laurent Gomila - SFML developer

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Reusing sockets and non-blocking sockets
« Reply #2 on: January 29, 2011, 06:10:49 pm »
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)?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Reusing sockets and non-blocking sockets
« Reply #3 on: January 29, 2011, 06:19:08 pm »
Quote
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.

Quote
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.
Laurent Gomila - SFML developer

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Reusing sockets and non-blocking sockets
« Reply #4 on: January 29, 2011, 06:25:32 pm »
Thanks for the speedy replies, Laurent! This clears a lot of confusion up :D

 

anything