websockets and php

2

Well, I have two direct doubts, which are:

  • Is the number of connections to the server limited? What limits that? is it possible to have infinite connections?

  • How can I send a message to a particular user according to this library?

For example there is A , B , C users and I wanted to send "Hi" to A and not B e C , I do not quite understand if this script sends to ID according to the establishment of the connection or if it uses the IP of the connected to send message, see the code that sends messages to all:

foreach ( $Server->wsClients as $id => $client )
            if ( $id != $clientID )
                $Server->wsSend($id, "Visitor $clientID ($ip) said \"$message\"");
  • Is it possible to check if the message was received? if yes, how can I check if A even received the message, or if it was "offline"

For example, I sent "Hi" to A but A was not connected to the server, or did not receive the message, how to tell me that this message can not be delivered?

I'm using this library in PHP to make my system work: GitHub

    
asked by anonymous 09.03.2015 / 03:40

1 answer

1

WebSockets maintains a persistent connection between client and server. There is no stone-bound limit, but the fact is that serving 10,000 clients with WebSockets will require a lot more from the server than serving 10,000 AJAX clients, because in AJAX only a small fraction of the clients are actually connected at any given time. p>

Sending messages is by ID, not by IP, each ID represents a TCP / IP connection, there may be several people connected to your service who are behind the same NAT router. Somehow you will have to associate the ID with other information that identifies client "A", "B" or "C" (eg could the client send a name as soon as it connects?).

To make sure that a message has arrived at the client, the client should send an "OK" message, in the format you specify. The wsSend () method returns true when the data could be sent, but this does not guarantee that the client has received, understood, or was able to process the message. (On the other hand, if wsSend () returns false, it is guaranteed that the client did not receive.)

    
13.08.2015 / 05:42