Hello, My game uses both TCP and UDP for communication. The TCP connection is established first, where a new UDP socket will be created on the server for this client only.
The port of this socket is chosen by the operating system (with the .NET UdpClient (int) constructor with a port number of 0). The port given is then sent back to the client via the TCP connection, which the client then uses to send UDP packets to the server.
The client will send a packet to the server, which will identify the client with the Socket.ReceiveFrom (byte[], ref EndPoint) method, where the EndPoint will contain the remote endpoint of the client.
This works locally and on an Azure VM with all ports open. It does not work in a game server allocated by through PlayFab. A client can connect with TCP, but the UDP "connection" fails. As I do not know this port before the client connects, I cannot specify this port in the build.
I have thought of two possible solutions: 1. As at most ~20 clients will be connected to the server at a time, I could specify 20 ports in the build for UDP communication, and then have the server allocate these ports to clients connecting, and reusing a port when a client disconnects. 2. Use just one port for UDP communication. The reason I don't do this in the first place, is that in order to get address that the server should send a UDP response back to, I have to use the Socket.ReceiveFrom method, which will create a new EndPoint object whenever an EndPoint different from the last is received from. As multiple clients will be sending data multiple ~60 times per seconds, this will generate a some amount of garbage. It might be insignificant, but I would still prefer to be without it.
How would I best solve this problem? Thanks in advance.