I have the following setup:
Dedicated server –> Internet –> Modem (telenet) –> Router –> client
- The client initiates a tcp connection with the server to register itself on the server, and gives through following info:
- mac address of the client
- external ip; this is retrieved by using webclient string download from whatsmyip.org
- Some updates occur on the server and of course the client needs to be notified, so the client can start a sync session on its own:
- To notify the client, the server sends a udp packet from the server to the modem (to the external ip, earlier received from the client), in the meanwhile the client is listening for udp packets behind the router.
The problem is that I’m not receiving any packets.. Is my scenario possible, what should I do?
Requirements:
- Solving this by enabling port-forwarding on the router isn’t an option
- The server has a fixed ip
- The client can be disconnected from the internet, at times
- The solution has to work on different kinds of routers
- Both ports at which packets are send & received are the same
- All programming is done in C#
- The server notifies the client when there is an update, the client may never poll the server for updates to prevent overload (in case several clients are doing this the same time)
Greets Daan & thanks in advance
EDIT:
Code example from 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();
Code example from 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); // handles incoming messages, this is never reached because no packets are received :-(
}
}
catch (Exception e)
{
Console.WriteLine("An error occured while listening to server broadcast updates: " + e.ToString());
}
finally
{
masterSyncUdpListener.Close();
}
}
Since you don’t have control of the NAT devices in the path, the only sane way here is to use TCP as your main transport.