views:

122

answers:

1

Hi,

I'm wondering how to implement a client management for a socket server.

I'm having the case where I would like to know whether the client has just reconnected or if it's a new client. I know, it shouldn't be that way. It's a rather temporarily server, though, which is only to be used for a couple of hours.

I was thinking about letting every client pass its own GUID to the server. Once the server "recognizes" a client, it can get rid of the previous-held connections of that client.

How would you approach this issue? Or is it completely unapproriate this way?

Thank you!

+1  A: 

If you are using TCP/IP, than you can use IP addres and port to uniquly identify clients. And you can get rid of your connection after disconnect event. If IP address and port is not enough to uniquly identify client, than you can use GUID. And again with TCP/IP in many cases you can get rid from connection after disconnect event.

Sergey Teplyakov
Thank you, I'd like to follow that GUID approach a little more. It would only make sense, if the server was being told what GUID each client has. Therefore, I would need to derive from `Socket` and add my GUID. But then I run into trouble handling all the methods from Socket, that return an instance of `Socket`.
rdoubleui
In most cases you should prefer composition to inheritance. I mean, that you should do not inherit from Socket, you should create your own class instead, that holds Socket and GUID.Or your server class may contain dictionary with Socket as a key and a GUID as a value.
Sergey Teplyakov
Ok, I see the point. My goal was, though, to identify each client upon connection (with the GUID) with the server. I guess I could send the GUID as the first message upon connection. I don't see any other way of doing that, do you? Thanks for your input!
rdoubleui
In WCF, for instance, for each session also bound GUID, so I think this is more or less common aproach.
Sergey Teplyakov