Trying otplatit message to the browser in swoole (websocket php), but not sent, like is sent?

Here is my code
create a server
<?php

class websocket
{
 public $ws;

 public function start()
{
 $this->ws = new swoole_websocket_server('127.0.0.1', 9502);

 $this->ws->on('open', function ($ws, $request) {
 echo "connection open: {$request->fd}\n";
});
 $this->ws->on('message', function ($ws, $frame) {
 echo "received message: {$frame->data}\n";
 $this->ws->push($frame->fd, json_encode(["hello", "world"]));
});
 $this->ws->on('close', function ($ws, $id) {
$this->onClose($id);
});

$this->ws->start();
}
}


Then the file which sends the message to the client browser

include ('websocket.php');
$n = new websocket();
$n->ws->push(1, "asdf", 1, true);


Here comes this error
127.0.0.1:51180 [500]: GET /send.php - Uncaught Error: Call to a member function push() on null in /home/jessyca6/Desktop/123/send.php:4

Or what not to do so ?
April 4th 20 at 00:40
1 answer
April 4th 20 at 00:42
Or what not to do so ?

$n->start();
This line stops
$n->ws->push(1, "asdf", 1, true);
displays this error
127.0.0.1:51180 [500]: GET /send.php - Uncaught Error: Call to a member function push() on null in /home/jessyca6/Desktop/123/send.php:4
- jessyca6 commented on April 4th 20 at 00:45
You code read it again. - pamela.Stark commented on April 4th 20 at 00:48

Find more questions by tags PHPWebSocket