Jump to content
  • Advertisement
Sign in to follow this  
silverphyre673

Just want to clarify something...

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am just starting to learn networking. Like all my other coding so far, I'm learning on my own through my own projects. I promise I won't bother you with questions about the M-word. Anyways, I just wanted to check something. If there were several people connecting to, say, a chat server, then could you identify them each individually by their IP address, no matter what? Let's ignore hackers for a moment. What I wonder is this: Say you had several computers sharing a single internet connection, connected through a router. Now, when you install the router, you assign it an IP address. So my question is, does it broadcast all the computers using it as having the same IP address? I assume not, since that would make it difficult to play MMO games from two computers on the same router, but I want to check. If so, then how do individual computers get identified uniquely? How much info is there to keep track of for each individual person signed onto a server, in terms of unique connection identification? Thanks for your time.

Share this post


Link to post
Share on other sites
Advertisement
OK. Sorry, obviously I am very new to this. So sockets are kind of like "holes" in your firewall/router that allow you to more or less directly connect to a server of some sort, right?

For example, I am currently logged in on this site. So there is a socket open in my router and firewall that allows my computer to connect directly to gamedev.net? And is there a single socket on the gamedev server that everybody connects to, or is one opened per client?

I'm sure I could figure out this stuff by reading more, but I just wanted to get these couple of points cleared up before I started.

Thanks again.

Share this post


Link to post
Share on other sites
A socket is like a connection. When you try to connect to gamedev a socket is created. That socket then connects to the servers socket which creates a new socket (One socket to listen for connections and one socker per connection). Then the sockets comunicate and then close.

Any tutorial on sockets will give this info and more.

Share this post


Link to post
Share on other sites
Actually, HTTP connections only usually exist until the data has been transferred, then they're closed. But never mind.
When you connect to gamedev.net, your PC opens a socket, and connects it to gamedev.net. At the GDNet server, it has one socket listening for connections, and when someone connects to it, it'll create a new socket. So at this point, if you're the only one connected, the server has a socket listening for connections, and one for transferring data to you. Your PC has one socket open, which is connected to the one on the GDNet server.

If you have two PCs behind a router, or any other NAT (Network Address Translation) device, then the server will see the two clients as having the same IP address, but they'll have different ports, and will have different sockets. When data is sent from the server to the client, it'll get sent to your IP address, and will be picked up by your router. The router has a NAT table of where to send data destined for a certain port, so it knows to send it to the correct machine on the network.
For example, if two PCs connect to a server, and PC 1 uses port 10000 on the router, and PC 2 uses port 10001 on the router, then when data comes from the server for PC 1, it'll be sent to your IP on port 10000. Your router will see that port 10000 goes to PC 1, so it'll forward the data to there.

This is why you can't host a server behind a router without telling the router to forward the port first. If someone tries to connect to your IP and you have a router, the router won't know where to send the data. It can't really send it to everyone on the network, because that would cause chaos. So it just drops the packet.

Share this post


Link to post
Share on other sites
Quote:
Original post by mike25025
All computers behind a router have the same IP address.


It's not quite that simple and it depends on exactly what you mean when you say "router".

First off, each computer actually has it's own unique (amongst themselves) IP address - if they didn't then there would be no way for them to talk to each other, nevermind going through the router.

When you say "router" you probably actually mean a NAT (network address translation). A NAT is used when your ISP only gives you one IP address yet you have to have a bunch of computers share it. What the NAT does is translate your machine's IP address into the one ISP has given you and back again creating a sort of virtual connection. This is what Evil Steve is talking about. Computers outside NAT will see a single IP address (with different ports). Inside the NAT they all use thier own addresses.

Other common usages of "router" are to mean a firewall - basically a layer of extra security and policy between two networks that may or may not also have NAT services. A switch - a piece of hardware with multiple network interfaces and enough smarts to efficiently choose which interface to use. And occasionally a hub - which is basically a really dumb switch that just rebroadcasts everything to all interfaces.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!