0

I want to develop a server for an application of mine in C++. I'm not really familiar with networking concepts. This server is going be a simple one and I'll use one of the networking libraries out there. I just couldn't figure out the necessary keywords to research the following issue:

Let's say that there are 100 users on 100 different computers, all sharing the same internet connection, behind the same router. They all decide to open my client to connect to my server. How do you deal with this issue if you want to keep the connections open and on the same port.

Charles
  • 107
  • 5
  • This isn't a good format for teaching networking concepts. You need a tutorial, like [this one](http://beej.us/guide/bgnet/). – Fred Larson Dec 21 '14 at 00:12
  • The network stack will handle all of that for you as long as you're using a TCP socket which you should be as there it's unlikely UDP will be used. You should get more familiar with networking concepts and API's. As it stands your question is too broad. – Captain Obvlious Dec 21 '14 at 00:17
  • Each TCP connection is uniquely identified by a 5-tuple: http://stackoverflow.com/a/15763717/131930 ... in your example case, it is the 'source port' member of the tuple that will be different for each of the 100 connections (but as Captain Obvlious says, the TCP stack will handle this detail for you so you don't have to worry about it in your program) – Jeremy Friesner Dec 21 '14 at 02:26

2 Answers2

1

This kind of server programming is not easy and requires network skills. You can have a look at this tutorial. It's C and unix, but it shows the function you'll need to use:

  • socket interface for network access
  • listening/accepting new connextion
  • forking new processes to handle the different clients (although in C++ you'd probebly look for multithreading which is more efficient for this kind of task).
Christophe
  • 68,716
  • 7
  • 72
  • 138
1

For the purposes of your server, it doesn't make any difference whether those 100 connections are all coming from the same computer, from the same router, or from totally separate networks.

While the server side of the connection will use the same port for all of these, each connection will have a different combination of client side IP address and port. In the case you describe, where all 100 are behind the same router using the same IP address, the router will take care of making sure they all have different client side port numbers. You can read about network address translation (NAT) if you want to learn the details about one common way that is done.

Russell Reed
  • 424
  • 2
  • 8