connecting a client and server app

Pages: 12
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
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
But how will the master server know the list of other servers?
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
Yes, that's exactly how it's done for nearly all existing games/software that do this.
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?
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.
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
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?
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
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
wouldn't firewalls cause a problem?
No, your clients won't be accepting incoming connections - they'll be sending outgoing connections.
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.
@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
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? ;)
LB wrote:
The server won't be the one with the firewall will it? ;)
It better be.
i'm sure the computer that is running the server will have a firewall
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.
so how do i get past the firewall?
Pages: 12