0
votes

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.

2

2 Answers

0
votes

Seems to me like a firewall issue. Please make sure that the port is open on your router to allow the port forwarding. Next head to your machine which runs the server application and verify that the port is open for remote connections.

If this is still not working install wireshark on the server application machine and monitor the network traffic with a port filter for TCP port 9081. There you can see if the requests from the client are reaching your server endpoint. Maybe check your client's machine that the outgoing port 9081 is not blocked, too.

0
votes

SOLUTION: I didn't click yes when the network asked me if I wanted my device to be recognized on this network when I first plugged in my cradle point router. I actually didn't answer yes or no and by default it chose no.