これは、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.
上記のシナリオでは、サーバーは同じコンピューターからログに記録されたさまざまなユーザーを区別できないため、ユーザーの状態が正しくありません。この問題を解決する方法を知っている人はいますか?