English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have finally gotten my client and server programs working that I was doing as an exercise. However, I would now like to get them to work with them being run on different computers, maybe just my lan, but really I'd like to know how to over the internet.

Currently, for the sockaddr_in struct, I am just doing:

sockaddr_in sockin;
sockin.sin_addr.s_addr = inet_addr("127.0.0.1");

and I am doing that on both the client and the server, because I was running the server and the client on my computer

What would I do if I wanted my program to work over the internet? Lan seems like it would be easy, but for internet I'm just lost.

2007-03-14 13:06:26 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

in response to the first answer:
i am aware that that is the local loopback, my problem is that I do not know what to put for server ip, i obviously cannot just put my 192.168... address, because that is the local lan address, and if the client was running somewhere else, it obviosuly wouldnt work over internet, but i wudnt imagine putting my routers external ip wud work, or wud it? idk, thats why im asking =S

2007-03-14 13:13:30 · update #1

2 answers

You need to get the IP address from the user or a configuration file; read it into a char array and pass that to inet_addr() macro instead of "127.0.0.1". There is no difference between doing it for a local network or over the Internet.

Additional:
To use your routers Internet IP, you would have to have Port forwarding setup to forward that connection to the computer that is running your server software.

2007-03-14 13:40:30 · answer #1 · answered by Chris J 6 · 2 1

Assign the client machine and server an IP address and replace the IP as needed. 127.0.0.1 is the loopback/localhost address. you're just telling it to connect to itself. If you replace it with the IP of the other host it should work fine. (assuming there are no firewalls getting in the way.)

Do your computers alredy have IPs assigned to them? if so you can just use those. If they don't have one assigned you can just pick whatever you want for your LAN machines. say 192.168.0.1 through 192.168.0.254? with a netmask of 255.255.255.0 default gateway can be skipped since it's not required for 2 machines to talk to each other if they are on the same subnet (which they will be with the IP range and netmask i suggested)

2007-03-14 20:09:43 · answer #2 · answered by mackn 3 · 0 0

fedest.com, questions and answers