1

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?

Ichigo Kurosaki
  • 3,555
  • 8
  • 35
  • 51
Ran Shorowitz
  • 127
  • 2
  • 11
  • 1
    Why are you trying to replicate TCP? – NomadMaker Jan 08 '21 at 12:56
  • I'm using GameMaker for a P2P client, and Java for a Matchmaking server. GameMaker has a built-in reliable UDP protocol between two GameMaker clients. But not one for GameMaker->Java. The Matchmaking server helps me connect players and also allow UDP holepunching between them. There is no way in GameMaker to get the UDP port you opened apparently, so I need to use UDP to connect to the Matchmaking server to get that port, which the server will in turn send my port to the proper players and we connect by sending multiple datagrams to holepunch the ports so port forwarding isn't necessary. – Ran Shorowitz Jan 09 '21 at 02:09
  • @NomadMaker Because he needs every feature TCP provides but can't use TCP because it's a direct connection between two machines behind NAT. – David Schwartz Feb 23 '21 at 18:51
  • @DavidSchwartz Maybe I'm missing something, but I've built TCP connections on such networks, behind the nat router. – NomadMaker Feb 23 '21 at 18:54
  • @NomadMaker NAT typically only allows an outbound TCP connection. It can't be outbound from both sides. – David Schwartz Feb 23 '21 at 18:55

2 Answers2

2

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!

Andrea
  • 141
  • 6
  • Thank you. Well it seems that it's extremely complicated to implement reliable UDP. I only need UDP so I can send the UDP port of my GameMaker P2P client to a Matchmaking Java server. There doesn't appear to be a way to open a UDP socket on GameMaker and get the UDP port without sending a datagram. If there was, I'd just use TCP to send the UDP port to the Matchmaking server, and then send the UDP port + IP to other players to attempt a UDP holepunch. GameMaker has a reliable UDP protocol so it'll be fast between 2 clients and also reliable. – Ran Shorowitz Jan 09 '21 at 02:13
1

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.

Sansonight
  • 21
  • 2