Realiable UDP - When does the TCP handshake occur?

290 Views Asked by At

Trying to develop a reliable UDP protocol for my game (made in GameMaker: Studio) that connects to a Java server. I need to ensure packets arrive and that they arrive in the correct order.

I'm trying to model off of the TCP protocol to do this, and one thing that's confusing me is the 3-way handshake: when does it occur?

Is the handshake basically when you first connect to something? It's only ever done once? (until the connection is dropped)

If that's the case, then what data am I attaching to regular packets?

Say I have my initial 3 packets for the connection: SYN -> SYN-ACK -> ACK

Let's assume this all went smoothly, boom we're connected.

And then let's say I want to send the server a message: "Hello". Am I basically doing SYN -> SYN-ACK -> ACK for this message? What exactly am I attaching to this message packet/datagram to ensure it arrives and arrives in order?

2

There are 2 best solutions below

0
On

In my experience, I used the UDP to send in broadcast a packet (just packet id to understand what i'm receiving) to get every servers created in the current network. Imagine 1 client called "A" looking for possible matches in the network. Other clients waiting for players are sending an UDP datagram in broadcast so everyone in that network know about them. After the client "A" connect to a match, the host is linking with "A" via TCP, to get a stable connection. To get the order of the packets, send an initial id digit, so when the client receive the packet know what he received ( ex. id=1 --> ping, id=2 --> player_position, id=3 --> hp_update ). You should get your way programmatically to get an order of the packets.

1
On

And then let's say I want to send the server a message: "Hello". Am I basically doing SYN -> SYN-ACK -> ACK for this message?

No. The packet is transmitted with no warranty.

What exactly am I attaching to this message packet/datagram to ensure it arrives and arrives in order?

You can add a sequential number in your packet and reorder them programmatically: if you receive packets 1,2,3 and than 5 you must wait for packet 4.

I need to ensure packets arrive and that they arrive in the correct order.

If you need both Re-transmission and ordered arrival (and probably avoid duplication), it is very difficult to do programmatically something better to TCP!