I'm currently trying to get an understanding of using port forwarding using a router to create a client/server relationship in C (Windows OS). I have been able to run two separate C programs on the same machine (one acting as a server that listens() and another program that acts as the client and connects() - From there they both exchange send()/recv() data no problem). My problem is when I try to use a router (Cradlepoint's IBR650C) to port forward so that I can run the Server program from one machine and the client program on another machine and have them send()/recv() data back and forth. I'm using TCP/IPv4 and Winsock Library.
I believe my issue is in understanding which IP's to specify as what. Here is the gist of my Server Program. Suppose, the IP address of Machine A running the server program is 10.0.0.109 (IPv4, Ethernet adapter Ethernet). The port that is available on that machine is 9081. I state in the server code on Machine A:
string ipAddress = "10.0.0.109";
sockaddr_in hint;
hint.sin_family = AF_INET;
hint.sin_port = htons(9081);
inet_pton(AF_INET, ipAddress.c_str(), &hint.sin_addr);
It reaches listen() and waits for a client to connect()
The IP address of the Cradlepoint router is 166.200.220.98 with the following port forward rule:
Internal Port(s): 9081 -> 9081
Local Computer 10.0.0.109
Local Port(s): 9081 -> 9081
Protocal TCP
The router is physically connected to Machine A via an Ethernet Adapter. The second machine, Machine B is not physically connected to either Machine A nor the router, and is running the client program which states as follows:
string ipAddress = "166.200.220.98"
int port = 9081;
sockaddr_in hint;
hint.sin_family = AF_INET;
hint.sin_port = htons(port);
inet_pton(AF_INET, ipAddress.c_str(), &hint.sin_addr);
The client then fails to connect() to the server. Is this correct reasoning in creating sockets using a router on two different machines? Should I add Inbound/Outbound rules in the Firewall for both machines? Should I add some default gateway and/or subnet mask to either machines via General Properties(TCP/IP v4)in Adapter Options?
ANY HELP IS APPRECIATED.