Thread: storing client data in server app

  1. #1
    sockets mad
    Join Date
    Mar 2002
    Posts
    126

    storing client data in server app

    I am currently starting work on a server application and am wondering as to the best way to store the information associated with each client connection (socket) such as nick, ip, description and any other data which i might need to store.

    At first i thought about creating a simple class to store this data and then creating a new instance of the class on the heap for each connection and adding the pointer to a CPtrList like class but my app does not (and hopefully will not have to) use MFC and I'm unaware of any other way of doing this without the the help of MFC.

    Any other ways anyone can suggest as to the best way to store information about currently connected users which is as fast as possible and uses as little memory as possible would be greatly appreciated. I need a method which can easily support 500+ concurrent users.

    Any help or suggestions would be very helpful. Many thanks in advance,

    Daniel

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    STL has some pretty good (and fast) containers if you are against using MFC and its containers.
    If you know how to use MFC (or write client-server software for that matter), then implementing your own CPtrList should be the easiest part of the project.

    gg

  3. #3
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    I've never written server software using C++ before and this is something I've wanted to do for a while. Bringing together what I've practiced and learn't about subjects like sockets and threads into one application. I haven't been using C++ for a long time so my knowledge isn't all that wide ranging, limited really only to the parts of C++ and the Windows API that I've used up until now and I apologise if my question was a dumb one.

    I was really only explaining my trail of thought on a possible way I thought of doing it in the hope some of the gurus around could give me some good pointers on methods of solving the problem I've got.

    The only real reason I didn't want to use MFC was it seemed like it was pointless to use it only for this one problem and I was sure there were other ways of solving it which were much better hence me posting asking for help.

    Thanks for the advice on pointer collections but I was wondering, is this the best way to go about it?

    tia

    Daniel
    Last edited by codec; 03-09-2003 at 09:27 PM.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Ah, well - if you want to use MFC just for CPtrList then go for it. If you link MFC staticly, the linker should only include code that you use - I may be wrong about the MS linker (too many tools to keep up with) but if you end up with all of MFC in your exe, just link dynamically to the MFC dll.

    A better solution is to learn STL containers like vector. STL is now part of the standard C++ library. I would recomend learning it and the rest of the standard C++ library as part of your C++ learning fun. If you are too hot and bothered to get busy on this project (I undersand if you are) then implement your own linked list in C++, not only to get comfortable with OO design/implementation, but also to use as your container for active connections.

    If you have never implemented a linked list, but you still want to take on a project of this magnitude, then you can use a simple array as your container of active connections.

    In the end, you'll have to balance: "what do I want to learn and use" with "what do I want to implement and use". I think that the time you'll invest in learning STL (if you don't already know it) will be payed back several times over by its reusability - if not on this project, then on every project you do from here on out.

    gg
    Last edited by Codeplug; 03-09-2003 at 10:19 PM.

  5. #5
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    Thanks for taking the time to give me such detailed advice.

    From what you say i think i'll deffinately be looking into STL as it seems very worthwile and re-useable. You're deffinately right in that I'm using this project to widen my knowledge and practice my skills. It's only really by practice that you fill in the gaps in you're knowledge after reading books etc.

    It's just as much about getting there as the finished product for me with this project and it should take some time but by the end of it I should have a much better understanding and hopefully a fairly well written piece of software to go with it.

    Thanks again,

    Daniel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to Send Mac Address From Client to Server
    By Lieyza197 in forum C Programming
    Replies: 2
    Last Post: 05-27-2009, 09:58 AM
  2. Sending data - line by line?
    By tuckker in forum C Programming
    Replies: 0
    Last Post: 02-21-2009, 09:31 PM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. Socket Programming Problem!!!!
    By bobthebullet990 in forum Networking/Device Communication
    Replies: 2
    Last Post: 02-21-2008, 07:36 PM
  5. Simple client - receiving data from server and keyboard w/o blocking
    By Spitball in forum Networking/Device Communication
    Replies: 5
    Last Post: 01-08-2005, 12:32 PM