Two connections have the same unique ID? How do I identify them?

nkorhonen

I am running WebSocket server (version 3.3.6) and I noticed a possible bug or at least a serious inconsistency: When I connect two clients to the server (localhost), both of them will have the same _$user->id_. There is no way of knowing who is who. Both connections start with a welcome message (client to server), for which the server responds with a (You are ID #x). Both browser tab receives it. Both connections are alive, none of them has been terminated.

How can two clients have the same $user->id at the same time?

Code:

$ws_worker->onConnect = function($connection) {
    echo "Opened " . $connection->id . "\n";
 };

$ws_worker->onMessage = function($connection, $data) {
    global $ws_worker;

    echo "New message " . $connection->id . "\n";
    $connection->send("You are ID #" . $connection->id);
};

$ws_worker->onClose = function($connection) {
    echo "Closed " . $connection->id . "\n";
};

Output result (event and the ID):

Opened 1
New message 1
Opened 1
New message 1

3561 1 0
1个回答

t182848232

May I know how many processes you set?
Because two processes may have the same connection id,
you can identify them by the _$connection->worker->id_ and the _$connection->id_.

  • 暂无评论
年代过于久远,无法发表回答
×
🔝