Thread: Multi-threaded server design question

  1. #1
    Registered User
    Join Date
    Mar 2004

    Multi-threaded server design question

    I have a primitive, in-the-works, IM server/client. The underlying principles:

    -Server has support for multiple client connections.

    -Currently, server only supports receiving usenames/passwords.

    -Clients send a message category (mCat) to the server, and the server acts accordingly (actAccordingly()), calling specific functions.

    -Server has a thread to accept connections from clients, and creates threads for each one.

    -Each of these threads runs a main loop;

    void clientsThread(int* s)
       int mCat = getmCat(s);
       [Check for any errors and deal with them (break, or continue)]
       [Check for any errors and deal with them (break, or continue)]
     [Remove any handles associated with this thread/socket]
    -The server does not use any mutex's, and doesn't use a FD_SET of all the clients connected(Should I need these?). I have arrays of index's of the clients, usernames associated with the sockets, handle to thread associated with the socket, etc.

    The problem I'm experiencing (if it's at all evident in the information I've supplied), is that clients' requests seem to get mixed up serverside, and undesireable effects happen, such as incorrect logins with correctly supplied un/pw's.

    I'm perplexed by this, as each client's request should be sovereignly handled with each of the correspondly threads, correct? Each thread should be able to invoke multiple instances of the same functions... They don't share any cross-thread/cross-socket data members...

    Any comments?
    Last edited by theroguechemist; 03-06-2004 at 07:56 PM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    In regard to your design, how do you destinguish among different clients?


  3. #3
    Registered User
    Join Date
    Mar 2004
    I just used the computers integer value of the socket connection stored in an array.

    But alas, I've gotten it workinga few days before. I'm ashamed to admit it was a flaw (a very simple one at that!) in my design and nothing else. But throughout all the debugging, I did manage to finally make each client have it's own thread, and I now use the mutex's..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux (not programming) E-mail server question.
    By Kennedy in forum Tech Board
    Replies: 4
    Last Post: 11-09-2006, 02:08 AM
  2. Question on returning stdout from a server
    By verbena1 in forum Networking/Device Communication
    Replies: 2
    Last Post: 04-29-2005, 12:59 PM
  3. problems in with design of a server project.
    By codec in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2003, 09:11 AM
  4. Replies: 4
    Last Post: 11-19-2002, 09:18 PM
  5. OO design question
    By PJYelton in forum C++ Programming
    Replies: 8
    Last Post: 10-10-2002, 12:52 PM