Sign in to follow this  
Aqua Costa

[C++] Socket servers

Recommended Posts

Aqua Costa    3691
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?

Share this post


Link to post
Share on other sites
rip-off    10976
[quote]
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 [url="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#getpeername"]discover the remote peer's address[/url] when it accepts a connection.

[quote]
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.

[quote]
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.

Share this post


Link to post
Share on other sites
Vortez    2714
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.

Share this post


Link to post
Share on other sites
Aqua Costa    3691
[quote name='Vortez' timestamp='1310340305' post='4833507']
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.
[/quote]

Hey,

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

I haven't tried it yet though...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this