connecting a client and server app

Pages: 12
May 30, 2013 at 1:06pm
I need to create a client and server program. The client will have a GUI that will display all the available servers (since more than one will be running) in a list box.
I’m guessing a TCP connection will be the best method here, but how will the client find the servers to connect to? I won’t know the IP address of the server because anyone could take the server program and run it on their computer and the client would have to find it.

Is there some way to make the server send some kind of signal that only the client application will be to connect to? So the server will be sending out a signal, the client finds the signal and connects to the server. Is this possible?

i also need to be able to store the IP address the client selects so when the client application is run again it will automatically connect to the server that was stored
Last edited on Jun 12, 2013 at 7:48am
May 30, 2013 at 1:30pm
Servers will need to identify themselves to one master server for which you know the IP address, then the client can ask that master server for the list of other servers.

To remember the last IP address, why not store it in the preferences/configuration file?
Last edited on May 30, 2013 at 1:31pm
May 30, 2013 at 1:36pm
But how will the master server know the list of other servers?
May 30, 2013 at 1:37pm
L B wrote:
Servers will need to identify themselves to one master server
I would have the other servers contact the master server every minutes and say "hey, I exist!", and if the master server doesn't receive this from a server on the list after two minutes, then remove that server from the list until it contacts you again later.
Last edited on May 30, 2013 at 1:38pm
May 30, 2013 at 1:48pm
Yes, that's exactly how it's done for nearly all existing games/software that do this.
May 30, 2013 at 1:49pm
ok so back to the question whats the best way to store the servers since now the master server and the client will need to able to store the ip address.
could you give more detail about a preferences/configuration file?
May 30, 2013 at 1:51pm
The master server doesn't need to store the server list since all the servers expire after 2 minutes of no communication.

The client gets the list from the master server, so it doesn't need to remember that.

The only thing you might want the client to remember after being closed and re-opened is the last server it connected to - just store that in a file.
May 30, 2013 at 1:57pm
so how does the master server remember the server list?

well i don't want the client to connect to the last server it used.
I want to use a remember me check box so only if this is clicked the client will remember the server it used
and if the check box isn't clicked then the client needs to display all the servers again the next time the client app is run so the user can connect to a different server
Last edited on May 30, 2013 at 2:03pm
May 30, 2013 at 2:22pm
beginner123 wrote:
so how does the master server remember the server list?
I don't understand what you want, why would it need to? It only needs to keep the list in memory.
beginner123 wrote:
well i don't want the client to connect to the last server it used.
I want to use a remember me check box so only if this is clicked the client will remember the server it used
and if the check box isn't clicked then the client needs to display all the servers again the next time the client app is run so the user can connect to a different server
Then do what I just said but only when the checkbox is ticked?
May 30, 2013 at 2:28pm
It only needs to keep the list in memory
yes thats what i mean. how will the master server do this?

what kind of file should i use for storing the server in the client app?
Last edited on May 30, 2013 at 2:28pm
May 30, 2013 at 2:38pm
beginner123 wrote:
yes thats what i mean. how will the master server do this?
How would it not? You're the one programming it right? Surely you know off the top of your head how to maintain a list of IP addresses in C++? If not, I would like to know why you are starting such an ambitious project as this - if you don't even know about std::vector then I don't kow how you could know about TCP socket communication.
beginner123 wrote:
what kind of file should i use for storing the server in the client app?
What do you mean "what kind of file"? There is only one kind of file. If you mean "what format", then pick any you choose. It can even be as simple as just storing the plain-text IP address. The file extension does not matter, as it has no relation to the content of the file.
Last edited on May 30, 2013 at 2:38pm
Jun 10, 2013 at 1:49pm
wouldn't firewalls cause a problem?
Jun 10, 2013 at 7:01pm
No, your clients won't be accepting incoming connections - they'll be sending outgoing connections.
Jun 10, 2013 at 10:31pm
i can see that beginner123 have some experience in networking, probably not enough for such application, but still good.
in the same time, you are still a beginner in C++, and you want to create a network application.
here's one advice: start with the basics, and go from bottom up.

i'm not that great in networking, i just have some modest info:

the client can broadcast a request to know if there's a server in the local network or not, if a server catches this broadcast, it replies to the exact ip address that sent the broadcast telling it that "hey, i'm a server, what do you want", the connection can go on from this point as you see fit.

i myself admit "i can't write this program", it needs really some good experience in using tcp/ip protocol and broadcasting, and some programming knowledge.
security here is a great concern, that implies some cryptographic protocols, and functions for (hashing, communication encryption, credentials ...etc) they are so complicated.

i think my method can really apply to local networks or so, i don't think it works on the internet, like a client in Australia, and a server in the UK.
Jun 11, 2013 at 1:56pm
@L B but the server will be accepting incoming connections from the client

@Rechard3 yes broadcasting is for local networks only so that won't work for my application
Last edited on Jun 11, 2013 at 1:56pm
Jun 11, 2013 at 4:55pm
beginner123 wrote:
@L B but the server will be accepting incoming connections from the client
The server won't be the one with the firewall will it? ;)
Jun 11, 2013 at 6:20pm
LB wrote:
The server won't be the one with the firewall will it? ;)
It better be.
Jun 11, 2013 at 6:24pm
i'm sure the computer that is running the server will have a firewall
Jun 11, 2013 at 7:57pm
beginner123, i don't really think this post should be here, as this is not a beginner's issue.

you may need to move it to General C++ Programming.
Jun 12, 2013 at 2:03pm
so how do i get past the firewall?
Pages: 12