George Austin
George Austin

Reputation: 23

Can you run a client application and a server application on the same host machine

I have a synchronous TCP server and client application the works absolutely fine on two separate host machines.

What I'd like to know is what IP and port do I bind the server socket and the client socket to when the applications are both running on the same host machine.

I can't find any solid information on Google about this. When I try and use my network IP which was 192.168.0.32 I get an error that says the Host actively refused the connection.

I cannot find any reasonable information about this error.

Can I listen and send on the same Port?

What IP address should I use to bind the server and the client, when both applications are running on the same machine?

Thanks for your time.

Upvotes: 2

Views: 9359

Answers (3)

Tamir Nakar
Tamir Nakar

Reputation: 1053

In order to run both client and server applications on the same host you should bind your server socket to localhost (you can actually write "localhost" it's a preserved word or 127.0.0.1 ) and address it from the client as well. Localhost allways refers to the computer you work on.

If you'd like to access your server from a machine which is outer to your local network using your network ip you've mentioned, you should first search for "IP FORWARDING" option in your router settings and forward incomming requests to the machine where the server is running on.

Or (my favourite) use the great IP TUNNELING service of ngrok. You can find it here https://ngrok.com/

good luck.

Upvotes: 2

The IP address could be the loopback 127.0.0.1 for both, or your IP address, I don't see why it would not work.

The port on the other hand has to be the same for it to work, assuming the client application doesn't also listens to the port that you "bind" it to.

You have to tell the server on which port it should listen. The client then has to send data on the same port for the server to get the information.

This example should get you going: https://www.codeproject.com/Articles/1415/Introduction-to-TCP-client-server-in-C

Upvotes: 0

George Austin
George Austin

Reputation: 23

So the answer to this question is that I must bind to my loop back address with separate ports for the client and the server !!

Upvotes: 0

Related Questions