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

Author Topic: TCP  (Read 3606 times)

0 Members and 1 Guest are viewing this topic.

Law

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
TCP
« on: September 01, 2015, 01:04:23 pm »
Hello,

I apologize if my question is dumb (probably is). Suppose I send an sf::Packet through an sf::TcpSocket. How do I know, from the sender's perspective, that the recipient has received the sf::Packet indeed?

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: TCP
« Reply #1 on: September 01, 2015, 01:11:45 pm »
The TCP protocol guarentees it. You could always send back a verification packet that doesnt contain anything but lets the client know that the server has received the packet.

Law

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: TCP
« Reply #2 on: September 01, 2015, 01:23:14 pm »
Okay so if the recipient lags or is experiencing a short Internet interruption, I can't know that he hasn't received the message yet?

Also, if 10 sf::Packets are sent while the recipient has briefly lost their connection, what would happen when they get it back? Would they receive all 10 sf::Packets in the same order they were sent?

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: TCP
« Reply #3 on: September 01, 2015, 01:49:50 pm »
An excerpt from https://en.wikipedia.org/wiki/Transmission_Control_Protocol:
Quote
TCP provides reliable, ordered, and error-checked delivery of a stream of octets between applications running on hosts communicating over an IP network.

So to answer your question and to build upon my answer: TCP will guarentee that your packets are delivered in the order they are sent, although you do not know when they are received so like I mentioned before, if you absolutely must know you can send back a packet. If you want to measure latency you can always send your packets with an epoch or some sort so you can measure time differences.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: TCP
« Reply #4 on: September 01, 2015, 01:54:28 pm »
Quote
Also, if 10 sf::Packets are sent while the recipient has briefly lost their connection, what would happen when they get it back?
If the socket gets disconnected, everything is lost and you must manually reconnect it. There's no auto-reconnection. But as long as the socket is connected, you can be sure that everything is delivred reliably.
Laurent Gomila - SFML developer

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: TCP
« Reply #5 on: September 01, 2015, 01:58:18 pm »
Laurent made a good point. Something interesting I suppose you could do is store a stack of packets that have been sent and give each one a unique identifier and when the server has received the packet, send another packet back to the server and pop from the stack or something so that way you know exactly what packets have been received. Probably a horrible idea. I'm not that great with design things.

Law

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: TCP
« Reply #6 on: September 01, 2015, 02:42:34 pm »
When I was talking of Internet interruption, I meant a duration of ~1/2/10 seconds, not ~1/2/10 minutes.  I suppose an sf::TcpSocket doesn't get disconnected for this kind of short duration.

Thanks everyone.