I have the following setup:
Dedicated server β Internet β Modem (telenet) β Router β client
- The client initiates a tcp connection with the server to register with the server and provides the following information:
- Client MAC Address
- external ip; this is retrieved by downloading the webclient line from whatsmyip.org
- Some updates happen on the server, and, of course, the client must be notified, so the client can independently start a synchronization session:
- To notify the client, the server sends the udp packet from the server to the modem (to the external ip previously received from the client), while the client listens for udp packets behind the router.
The problem is that I do not receive any packages. Is my script possible, what should I do?
Requirements:
- Solving this by enabling port forwarding on the router is not an option
- The server has a fixed ip
- The client may be disconnected from the Internet from time to time
- The solution should work on different types of routers.
- Both ports on which packets are sent and received are the same
- All programming is done in C #
- The server notifies the client when there is an update, the client can never interrogate the server for updates to prevent overload (in case several clients do this at the same time)
Welcomes Daan and thanks in advance
EDIT:
Sample code from the server:
UdpClient udpSender = new UdpClient(); IPEndPoint localServerGateway = new IPEndPoint(IPAddress.Parse(externalIp), 8003); string message = "testmessage"; byte[] messageBytes = Encoding.ASCII.GetBytes(message); try { udpSender.Send(messageBytes, messageBytes.Length, localServerGateway); } catch (Exception error) { Console.WriteLine("Error while sending message: " + error.ToString()); } udpSender.Close();
Example code from the client:
private void listenForMasterSyncRequest() { bool done = false; IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, 8003); try { while (!done) { byte[] bytes = masterSyncUdpListener.Receive(ref groupEP); handleMessage(bytes, bytes.Length, true);
source share