Hey all,
I coded a UDP server and client with C++ and I'm trying to get them to connect to each other over the global Internet. Here's what I've done:
1. Code
Client:
int portShift = 0;
socket.open(0);
dispatcher = new MessageDispatcher();
//set variables for connecting to the server
serverAddress.sin_port = htons((unsigned short)10203);
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = inet_addr("68.64.208.244");
//...
Server:
socket.open(10203)
//...
My socket wrapper:
bool EonSocket::open(unsigned short port)
{
//set up winsock and variables.
if(!initializeSockets())
{
logString("Winsock initiation error", LOG_FATAL);
return false;
}
message = EonMessage();
//create socket and check for errors.
handle = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if ( handle <= 0 )
{
logString("failed to create network socket", LOG_ERROR);
return false;
}
//create socket address
sockaddr_in address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
#ifdef EXODUS_SERVER
address.sin_port = htons(port);
//bind socket and look for errors.
if ( bind( handle, (const sockaddr*) &address, sizeof(sockaddr_in) ) < 0 )
{
logString("failed to bind network socket", LOG_ERROR);
return false;
}
#endif
//check for errors (omitted)
//we're done.
logString("set up socket", LOG_INFO);
return true;
}
As you can see, my socket binds on the server but not on the client, and in both cases everything works.
2. IP
My server computer has local IP address 10.0.0.6, and my router has a static IP address, which is why I'm using inet_addr instead of gethostname in my client.
3. Port Forwarding
I'm 96% sure that the port forwarding is set up correctly. I've checked the user documentation for my router and followed the instructions to the letter to forward port 10203 to my local machine 10.0.0.6
4. Firewall
Every time I test this, I ensure that my firewall is completely disabled. I will try it with the firewall once I'm sure it works w/o it.
5. WireShark
When I run Wireshark on my machine (I'm trying to run the client on the same machine as the server for now), I get the following output:
10.0.0.6 68.64.208.244 UDP Source port: trp Destination port: 10203
68.64.208.244 10.0.0.6 ICMP Destination unreachable (Port unreachable)
This makes me think that my problem actually IS related to port forwarding, but I used the PFPortChecker utility from portforward.com and it tells me that UDP port 10203 is open. What I really don't get is the Source port: trp thing because I'm not setting the port at all in the client code.
By the way, all my code works if I replace my static IP address in the client code with "127.0.0.1".
Anyone have any ideas? Did I just miss something stupid?
Thanks in advance,
Kukanani