0
votes

I'm currently developing an online game. Within the game it is necessary to send data from the server to the clients via TCP and UDP. Implementing UDP-Hole Punching is easy, but I'm not really sure how to implement TCP-hole punching:

  1. Server: ServerSocket listening on given port 1
  2. Client: Socket (object) connects to server on port 1 using port 2
  3. Once the connection is established, the server keeps the Socket object from server.accept() and uses it to send data to client for the remaining time
  4. Once the connection is established, the client closes its Socket object and opens a ServerSocket on port 2. The server is now able to send data using a Socket object on port 1 to port 2.

Is 3. or 4. the right way to go?

1

1 Answers

1
votes

Option 3.

Option 4 does not work because once the client closes the socket BOTH sides shut down. The server would have to initiate the connection across the NAT firewall, which clearly doesn't work.