发送消息后,工人突然关闭

时间:2019-11-21 04:35:32

标签: php websocket

我正在使用SQL> SELECT * FROM NLS_DATABASE_PARAMETERS 2 WHERE PARAMETER = 'NLS_CHARACTERSET'; PARAMETER VALUE ---------------------------------------- ---------- NLS_CHARACTERSET AL32UTF8 SQL> SQL> CREATE TABLE "LIGNE DE COMMANDE" ( 2 LIGNE_COMMANDE_ID NUMBER(6) 3 CONSTRAINT LIGNE_COMMANDE_ID_PK PRIMARY KEY, 4 "QUANTITÉ" NUMBER(3) 5 CONSTRAINT LIGNE_COMM_QTT NOT NULL, 6 ARTICLE_ID NUMBER(6), 7 -- CONSTRAINT LIGNECOMM_ARTICLE_FK 8 -- REFERENCES ARTICLE ( ARTICLE_ID ), 9 "CATÉGORIE_ID" NUMBER(6), 10 -- CONSTRAINT LIGNECOMM_CATÉGORIE_FK 11 -- REFERENCES CATÉGORIE ( CATÉGORIE_ID ), 12 COMMANDE_ID NUMBER(6) 13 -- CONSTRAINT LIGNECOMM_COMM_FK 14 -- REFERENCES COMMANDE ( COMMANDE_ID ) 15 ); Table created. PHP库创建WebSocket服务器。

workerman

一切正常。因此,我使用此类来发送消息Web套接字服务器:

require dirname(__DIR__) . '/vendor/autoload.php';

use Workerman\Worker;

// Create a Websocket server
$ws_worker = new Worker("websocket://0.0.0.0:8047");

// 4 processes
$ws_worker->count = 4;

// Emitted when new connection come
$ws_worker->onConnect = function($connection)
{
    echo "New connection\n";
};

// Emitted when data received
$ws_worker->onMessage = function($connection, $data)
{
    var_dump($data);

    // Send hello $data
    $connection->send('hello ' . $data);
};

// Emitted when connection closed
$ws_worker->onClose = function($connection)
{
    echo "Connection closed\n";
};

// Run worker
Worker::runAll();

有时会输出此错误:

// https://github.com/Textalk/websocket-php

$client = new Client('ws://127.0.0.1:8047/');
$client->send('test !');

如果重新启动服务器,它将再次运行...但是每次关闭发送连接后。我不明白为什么连接会关闭。

// Validate response.
if (!preg_match('#Sec-WebSocket-Accept:\s(.*)$#mUi', $response, $matches)) {
    $address = $scheme . '://' . $host . $path_with_query;
        throw new ConnectionException(
         "Connection to '{$address}' failed: Server sent invalid upgrade response:\n"
         . $response
    );
}

0 个答案:

没有答案