Archived

This forum has been archived. Please start a new discussion on GitHub.

Client Identification

I've got a bunch of clients connecting to a server, and I am storing data on the server for each of them. In my server implementation, how can I identify a client uniquely?

Client A connects to the Server, and I create some data for them.
Client B connects to the Server, and I create some data for them.

Client A asks the server for data, and I need to return the data which was created for them.

Right now, I am just giving them a unique ID when they connect, and the client passes it to the server on each call.

Is there a better way to do this?

Comments

  • What you are doing is one option of dealing with this issue. Another option is to have the clients create a session object in the server when they start, interact with the session object to manipulate the data (so the identity of the client is implicit in the session object), and destroy the session object when they are done.

    This approach is more OO in style and encapsulates the client identity. The down side is that you must deal with abandoned session objects that are left behind by clients that do not disconnect in an orderly fashion. An evictor is useful in this case. (See the doc in the server-side run time chapter for more details on evictors.)

    Cheers,

    Michi.
  • Thanks, that makes sense. I'll just stick with my current implementation, since I don't think I'll gain anything apart from more OO'ness at the cost of redesign.