Socket Server:管理客户端连接
我想知道如何为套接字服务器实现客户端管理。
我遇到这样的情况,我想知道客户端是否刚刚重新连接或者是否是新客户端。我知道,事情不应该这样。不过,它是一个相当临时的服务器,只能使用几个小时。
我正在考虑让每个客户端将自己的 GUID 传递给服务器。一旦服务器“识别”出某个客户端,它就可以删除该客户端之前保持的连接。
您将如何处理这个问题?还是这种方式完全不合适?
谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 TCP/IP,则可以使用 IP 地址和端口来唯一标识客户端。和
您可以在断开连接事件后解除连接。
如果IP地址和端口不足以唯一标识客户端,则可以使用GUID。同样,在许多情况下,使用 TCP/IP,您可以在断开连接事件后摆脱连接。
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.