websockets and php

Asked

Viewed 210 times

2

Well, I have two direct doubts, which are:

  • is limited the number of connections to the server? what limit does it? is it possible to have infinite connections?

  • How could I send a message to a particular user according to that library?

For example exists A, B, C users and I wanted to send "Hi" to A and not to B e C, I did not understand very well if this script sends to the 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 received even the message, or if she was "offline"

An example, I sent "Hi" to A but A was not logged on to the server, or did not receive the message, such as telling my person that this message cannot be delivered?

I am using this PHP library to make my system work: Github

  • Read the question http://answall.com/questions/61002/enviar-messagingpara-usu%C3%A1rio-espec%C3%Adfico-em-websocket-php/98407#98407

1 answer

1

Websockets maintain a persistent connection between client and server. There is no limit written in stone, but the fact is that serving 10000 clients with Websockets will require much more of the server than serving 10000 clients with AJAX, because in AJAX only a small fraction of the clients is actually connected every moment.

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

To make sure a message has reached the customer, the customer must send a "OK" message in the format specified by you. The wsSend() method returns true when the data could be sent, but this does not guarantee that the client has received, understood or managed to process the message. (On the other hand, if wsSend() returns false, it is guaranteed that the customer has not received.)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.