P
P
polzovatel_vue2019-12-18 13:22:55
Laravel
polzovatel_vue, 2019-12-18 13:22:55

How to install websocket on Lumen (Laravel)?

I can’t solve this problem: I installed the websocket package
on Lumen I took the most common example examples, Server:

require_once('vendor/autoload.php');

$socket = new \HemiFrame\Lib\WebSocket\WebSocket("localhost", 8080);
$socket->on("receive", function($client, $data) use($socket) {
  foreach ($socket->getClients() as $item) {
        /* @var $item \HemiFrame\Lib\WebSocket\Client */
    if ($item->id != $client->id) {
      $socket->sendData($item, $data);
    }
  }
});
$socket->startServer();

client
require_once('vendor/autoload.php');

$socket = new \HemiFrame\Lib\WebSocket\WebSocket('localhost', 8080);
$socket->on("receive", function($client, $data) use($socket) {
});
$client = $socket->connect();
if ($client) {
  $socket->sendData($client, "Message");
  $socket->disconnectClient($client);
}

set port 8080, they work with each other as they should, the client sends, the server receives ...
I try in js:
var conn = new WebSocket('ws://sender.com:8080/api/echo');
  console.log(conn);

Returns: WebSocket connection to 'ws://sender.com:8080/api/echo' failed: Error in connection establishment: net::
ERR_CONNECTION_REFUSED /api/echo", with http and https, with ws and wss, Localhost:8080/api/echo ...)
If I set the standard port 80, it shows: WebSocket connection to 'ws://sender.com/api/ echo' failed: Error during WebSocket handshake: Unexpected response code: 404
Apparently, the routing works and does not work, even if the route is registered, it will give the same error, only with the status code 200.
What to do in this case?
PS. Links replaced from bots, fix in development

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2019-12-18
@Austin_Powers

Have you var conn = new WebSocket('ws://sender.com:8080/');tried that?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question