Thread: Socket question

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    Question Socket question

    Ok I'm tring to write some code to make a server for a game that will accept 50 clients.

    can I have 50 sockets all looking to one port without them being confused and reading each others data? Like i dont want player a's command to be interperated as player b's command by the server.

    Since they are all looking at the same port im not sure if it will work.

    Also if I use just 1 port is it still safe to check for new incoming connections on the port with a "listener" socket (all it does is see if some1 is there then accepts the connection to another open socket then releases itself.)

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    each accepted connection will be given a unique file descriptor. Use this to keep track of whats what.

  3. #3
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    ok so its alright to have one looking at the port for new connections and the others for the actual game data. Thanks

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    120
    Your game SERVER will listen on a single port. All your clients will INITIATE a connection on that single port. Once the server ACCEPTS the connection, a new socket is opened (or new file descriptor, handle, whatever your OS uses). So each of those 50 connections will be on a different socket (and possibly a different port). You just have to juggle the communications with 50 different sockets. Hope thats clearer on how it works.

  5. #5
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Thats pretty much what I ended up doing...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket Question
    By BENCHMARKMAN in forum C Programming
    Replies: 15
    Last Post: 03-12-2008, 09:57 PM
  2. Socket program
    By mhetfield in forum C Programming
    Replies: 5
    Last Post: 04-03-2007, 03:46 PM
  3. Slight problem with socket reading!!!
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 02-15-2006, 09:55 AM
  4. problem closing socket
    By Wisefool in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-29-2003, 12:19 PM
  5. Simple Socket Question
    By SourceCode in forum Linux Programming
    Replies: 2
    Last Post: 06-22-2003, 09:20 PM