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:
- Server: ServerSocket listening on given port 1
- Client: Socket (object) connects to server on port 1 using port 2
- 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
- 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?