[C++] Socket servers

Started by
3 comments, last by Aqua Costa 12 years, 9 months ago
I want to do something like this:
-When server is turned on it stores its IP in an online DB.
-The client reads the IP stored in the DB and connects to the server using the IP.

The problem is that I never managed to connect a client and a server using sockets without using "localhost" has IP address.
-How can I get the server IP address using C++?
-Do I have to open the ports I want to use in my socket? How do I open them?
-Can I use "default" open ports?
Advertisement

How can I get the server IP address using C++?
[/quote]
You generally don't want to do this. First, you may have multiple interfaces, with different IP addresses. Also, the server could be behind a NAT. Instead, the online database should discover the remote peer's address when it accepts a connection.


Do I have to open the ports I want to use in my socket? How do I open them?
[/quote]
If you are behinda firewall or NAT, yes. How to do so varies with the firewall/NAT.


Can I use "default" open ports?
[/quote]
There are a handful of ports that are almost certainly open for outgoing connections, like HTTP and HTTPS for example. The default on many networks is to have no open ports for incoming connections.
Looks like this is my problem: http://www.mindcontrol.org/~hplus/nat-punch.html
Hi, im also having problem with my app because of routers behind nats, i've read the article above and understand most of it, but it says at the end that the introducer/server ..."can be run without paying huge bandwidth bills for servers". This leave me with the question, if the "introducer server" cant be run by both clients behind routers, what do you use to build such a system? A Web page using PHP? I've read somewhere else that most web pages hoster wont let code run indefinitely.

Sorry if my question is not clear but it would be nice to have example of how to implement such a system.

Hi, im also having problem with my app because of routers behind nats, i've read the article above and understand most of it, but it says at the end that the introducer/server ..."can be run without paying huge bandwidth bills for servers". This leave me with the question, if the "introducer server" cant be run by both clients behind routers, what do you use to build such a system? A Web page using PHP? I've read somewhere else that most web pages hoster wont let code run indefinitely.

Sorry if my question is not clear but it would be nice to have example of how to implement such a system.


Hey,

check these articles:
-http://lifehacker.com/software/feature/special-how-to-access-a-home-server-behind-a-routerfirewall-127276.php
-http://lifehacker.com/124212/geek-to-live--how-to-set-up-a-personal-home-web-server

I haven't tried it yet though...

This topic is closed to new replies.

Advertisement