Jump to content
  • Advertisement
Sign in to follow this  
Side Winder

What's the process of a user connecting to a server?

This topic is 3791 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'm looking to build a Chat server that users connect to and.. chat... Anyway, what's the order of things that has to happen in order for the users to connect to the server? For example, first of all, the server has to specify a port for the users to connect to, and also the IP address... What else needs to be done and in what order? edit: sorry, I should clarify. I'm looking at TCP here. [Edited by - Side Winder on March 3, 2008 7:24:54 AM]

Share this post


Link to post
Share on other sites
Advertisement
The server app creates a socket with a specific port number to 'listen on'
when it 'hears' a client trying to connect, it spawns a new tcp socket (on a new port) thats linked to that client (you probably want to make a new thread for it as well) and resumes listening on the orignal port.

a client creates a socket and tries to connect to the servers listen port (but ends up linking to the new one).

The server can't specify it's IP - the client will either have to know it already, or you'll need someway to 'broadcast' the server's IP.
For example if you have a static master-server that servers connect to, then a client can connect to the master server and ask for a list of available servers.

Share this post


Link to post
Share on other sites
Quote:
it spawns a new tcp socket (on a new port)


No, it retains the same port number on the server. There can be multiple sockets open with the same port number, as long as the remote endpoint (IP + port) is different for each. Thus, each new outgoing TCP connection to a given host will use a new port number on the initiating side.

In general, I think most of the questions in the original post are answered in the Forum FAQ, including some pseudo-code showing how a chat client and server will work.

Note that one thread per client is a terrible way of building server software, as it won't scale particularly well, and introduces all kinds of threaded race conditions in to your code. It's much better to use select() in a single thread, at least until you know better what it is you're doing, and can tune specifically for that.

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!