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

Author Topic: Receiving packets  (Read 2197 times)

0 Members and 1 Guest are viewing this topic.

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Receiving packets
« on: November 13, 2012, 11:11:16 pm »
I'm starting to work the thinking of my network programming and since I am still new to network programming I need a little help. When I receive a packet, I understand it can fail and go into an invalid state if I read more than the packet has. What exactly does this mean?

Second, the tutorial shows it extracting everything from the packet in the same line. Can I instead pull the first bit of information from the packet, x in this case, then do some sort of if statement and decide to pull the next bit of information from the packet.  My idea is to have the first bit of each packet sent be a variable that tells the receiver what the packet is, IE is this a chat message that needs to be handled by the chat portion or is it some game info and if so what kind of game info so the packet is not over extracted.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Receiving packets
« Reply #1 on: November 14, 2012, 08:06:00 am »
Quote
When I receive a packet, I understand it can fail and go into an invalid state if I read more than the packet has. What exactly does this mean?
What do you mean? ;D
When you reach the end of the packet you can't read anymore. Just like with standard streams. Or any class from which you can read. So what's your problem with that?

Quote
Second, the tutorial shows it extracting everything from the packet in the same line. Can I instead pull the first bit of information from the packet, x in this case, then do some sort of if statement and decide to pull the next bit of information from the packet.
Yes. Don't hesitate to play with your code and try things directly ;)
Laurent Gomila - SFML developer

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Re: Receiving packets
« Reply #2 on: November 14, 2012, 02:58:52 pm »
Well, the way it's stated in the tutorial it sounded like it was a bad thing to read past the end of the packet; like it would cause some sort of run time crash or something.

 

anything