I’m developing a client/server multi-player interface for my game using C# sockets. Both client and server uses UDP packets. When I setup the server and client to work on localhost, client connects and works just fine, however when I create a client version that should connect to server from the Internet, server never receives client’s UDP packets(client is stuck in connection phase).
Server is bound on port 1337.
What could be the causes of why the server wouldn’t receive connection from the Internet?
Here’s sockets setup code:
Client
```csharp
**public string serverEP;
public int serverPort;
IPEndPoint serverEP;
EndPoint rEP;//remote End point
bool connectionMessage = true;
//Socket creation
serverEP = new IPEndPoint(IPAddress.Parse(serverIP),serverPort);
clientSocket = new Socket (AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);//Server end point
rEP = new IPEndPoint(IPAddress.Any,0);
//Sending and receiving of data
//Receiving in Start function
GameHeader hdr = new GameHeader();
clientSocket.BeginReceiveFrom(recvBuffer,0,
MAX_PACKET_SIZE,
SocketFlags.None,
ref rEP,
OnReceive,
hdr);
//Sending
//In Update function
if (connectionMessage)
{
Connection conn = new Connection (username);
sendBuffer = conn.ToNetworkMessage ();
GameHeader hdr = conn.gameHeader;
clientSocket.BeginSendTo (sendBuffer, 0, sendBuffer.GetLength(0),
SocketFlags.None, serverEP,
OnSend,
hdr);
}**
```
Server
```csharp
**public int port;
Socket serverSocket;
EndPoint clientAddress;
bool connectionConfirmationMessage = false;//Gets set to true if server receives connection packet from the client.
//Server socket creation
serverSocket = new Socket (AddressFamily.InterNetwork,
SocketType.Dgram,
ProtocolType.Udp);
IPEndPoint ipEP = new IPEndPoint (IPAddress.Any, port);
serverSocket.Bind (ipEP);
//Receiving and sending of data
//Set in Start function
//Receiving
GameHeader hdr = new GameHeader ();
recvData = new byte[MAX_PACKET_SIZE];
serverSocket.BeginReceiveFrom (recvData, 0, MAX_PACKET_SIZE,
SocketFlags.None, clientAddress,
OnReceive,
hdr);
//Set in Update function
//Sending
if (connectionConfirmationMessage)
{
GameHeader hdr = new GameHeader ();
ConfirmationMsg cmsg = new ConfirmationMsg(true);
sendData = cmsg.ToNetworkMessage ();
serverSocket.BeginSendTo (sendData, 0, sendData.GetLength (0),SocketFlags.None,clientAddress,OnSend,hdr);
}**
```
If you need any more information to help me, I’ll update the main post.