Hoa\Websocket, hack book – Hoa


#1

The WebSocket protocol allows a bidirectional and full-duplex communication between a client and a server. The Hoa\Websocket library allows to create WebSocket servers and clients.


This is a companion discussion topic for the original entry at https://hoa-project.net/En/Literature/Hack/Websocket.html

#2

Automatic backup from previous comment system

Anonymous said (Tue Apr 07 2015 19:31:52 GMT+0200 (CEST)):

Hi, I’m trying to use with Laravel 5 Framework but I get the following error:

Server cannto join tcp://192.168.10.10:8889 and returns an error(number 0): Address already in use.

I installed within my Vagrant Homestead Machine.

Is there any problem using within a Framework or maybe is for some port issue?

Thanks in advanced


#3

Automatic backup from previous comment system

@Hywan said (Fri Apr 10 2015 09:22:45 GMT+0200 (CEST)):

It means that your server is already running. You cannot start 2 servers listening on the same IP.


#4

Automatic backup from previous comment system

Nicolas said (Tue Nov 03 2015 17:13:54 GMT+0100 (CET)):

So how to check if the server is already running before running it again ?


#5

Automatic backup from previous comment system

ibrahimab said (Tue Jan 26 2016 16:57:02 GMT+0100 (CET)):

sudo lsof -i


#6

Automatic backup from previous comment system

hosein said (Wed Apr 15 2015 16:53:46 GMT+0200 (CEST)):

how can I send a message for specific node? my code is:

$nodes = $bucket->getSource()->getConnection()->getNodes();

foreach ($nodes as $node) {
   $username = $node->getPseudo();
   if ($username == "ali") {
       $node-> ?????????????? -> send ("example")
   }
}

and can I select a node without using foreach but just with Pseudo of node?


#7

Automatic backup from previous comment system

@Hywan said (Thu Apr 16 2015 08:53:27 GMT+0200 (CEST)):

Hello :-),

You can try with the broadcastIf method. We opened an issue to update the documentation.


#8

Automatic backup from previous comment system

apoq said (Tue Sep 29 2015 15:28:48 GMT+0200 (CEST)):

$nodes = $server->getConnection()->getNodes();
foreach($nodes as $node)
   if($node->getPseudo() == "node-pseudo") 
      $server->send("message", $node);

#9

Automatic backup from previous comment system

hosein said (Sun Apr 19 2015 18:15:03 GMT+0200 (CEST)):

when I send binary message for example a JPG file , HOA work’s fine and send it completely on local machine (wamp) but when I test it on server (vps linux) , that file would be received corrupted . I don’t know why . please help


#10

Automatic backup from previous comment system

@Hywan said (Thu Sep 24 2015 12:19:15 GMT+0200 (CEST)):

This is possible your service stops the connection because this is too much heavy. Could we have more information?


#11

Automatic backup from previous comment system

Hyarion said (Fri Sep 25 2015 17:36:37 GMT+0200 (CEST)):

Is it possible to get the ip address of the connection that sends a message? $bucket->getSource()->getConnection() just seems to return the same ip as the server. Or even a unique identifier for each connection?


#12

Automatic backup from previous comment system

@Hywan said (Wed Oct 14 2015 10:26:34 GMT+0200 (CEST)):

Please open an issue on Github for this kind of question: https://github.com/hoaproject/Websocket. Thanks!


#13

Hello there, thanks for the awesome library Been having trouble with closing the connection of a specific node The documentation here says that the close function takes 3 arguments with the third being the node marked for closing But everything i try ends with the current node closing rather than the specified node I’ve looked into the implementation and the close function does not take a third node parameter and that it actually always closes the current node Any help would be appreciated Thanks


#14

Hello @yehia,

You’re absolutely correct! This is an issue in the documentation. Sorry for that! I have opened https://github.com/hoaproject/Websocket/issues/86 to address it. Do you want to try a fix?


#15

Thanks a lot for the fast reply @Hywan

Sure I would like to try a fix, I’ve been trying for 3 days, I’ve even tried to use the connections iterator to close a specific node which isn’t optimum since i have to loop through all opened connections but even this didn’t work The iterator always had only the last item even if i call the rewind function manually it still only had one item which is the last one

Sorry for the long explanation and thanks again for the library and the support


#16

Did you simply try the following code:

$node->getConnection()->close(…)

#17

Always closes the current node, I’ve also tried

$nodes = $connection->getNodes()
$nodes[$nodeId]->getConnection()->close(…)

Still closed the current node seems that they are all sharing the same instance or the $_node variable was always holding the latest node

Or maybe I’m missing something

Edit: Tried $nodes[$oldNode->node_id]->getProtocolImplementation()->close(); Still closed the last node