【发布时间】:2013-12-23 13:57:02
【问题描述】:
这是一个基于 UDP 协议与所有客户端通信的 C++ 服务器应用程序。当用户从客户端登录到服务器时,客户端应用程序向服务器注册一个UDP通道,该通道的格式是固定的:IP+Port,即如果IP保持不变,那么无论客户端登录的用户注册什么同一个频道。
服务器的套接字层维护一个心跳机制,如果它在 3 分钟内没有收到来自通道的任何心跳数据包,它将删除该通道。一切正常,直到客户端关闭,例如网线被拔掉了。看下面的场景:
1. User-A logs into server. The Client registers channel (IP:Port)
to the server. Because the UDP channel is alive, so the Server
sets the User status of User-A as Online.
2. Kill the client process, and within 3 minutes(before the channel
timeouts in server), let User-B logs into server from the same
computer. Because the IP remains unchanged, so actually the client
registers a same (IP:PORT) pair to the server as it did when User-A
logs in.
3. Since the Server receives packets from (IP:PORT), so it considers
User-A is still alive, thus setting the user status of User-A as
Online which is not right anymore.
在上述情况下,服务器无法区分从同一台计算机登录的不同用户,从而导致用户状态错误。有谁知道如何解决这个问题?
【问题讨论】:
-
你可以实现某种身份验证。
-
将频道签名从
(IP:PORT)扩展到(IP:PORT:USER)
标签: linux networking udp client-server heartbeat