The problem of Socket.io and Workerman

Source: Internet
Author: User
Tags autoloader
Has anyone ever played these two things? Both can use the WebSocket protocol,
and the Workerman server OnConnect has been executed, indicating that the client and the server can be contacted.
But why is the connection immediately disconnected? And the server did not receive the information sent by the client.

Workerman Service-side code:

use Workerman\Worker;require_once '../Workerman/Autoloader.php';$worker = new Worker('websocket://0.0.0.0:8484');$ws_worker->count = 4;$worker->onConnect = function($connection){echo "new connection from ip " . $connection->getRemoteIp() . "\n";};$worker->onMessage = function($connection, $data){var_dump($data);$connection->send('receive success');};$worker->onError = function($connection, $code, $msg){echo "error $code $msg\n";};$worker->onBufferFull = function($connection){echo "bufferFull and do not send again\n";};$worker->onBufferDrain = function($connection){echo "buffer drain and continue send\n";};$worker->onClose = function($connection){echo "connection closed\n";};$worker->onWorkerStop = function($worker){echo "Worker stopping...\n";};$worker->onWorkerStart = function($worker){echo "Worker starting...\n";};

Client code: Using the Socket.io, which is an Android app

private Socket mSocket;{    try {        mSocket = IO.socket("websocket://192.168.0.11:8484");    } catch (URISyntaxException e) {}}@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main_activity1);    mSocket.connect();    mSocket.emit("hello", "hello world");    mSocket.emit("emit something");    mSocket.send("send something");    mSocket.send("hello","thanks");}

Why does it occur when the connection just disconnects, and the information is not received. These are the information that the server receives.

new connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3

Reply content:

Has anyone ever played these two things? Both can use the WebSocket protocol,
and the Workerman server OnConnect has been executed, indicating that the client and the server can be contacted.
But why is the connection immediately disconnected? And the server did not receive the information sent by the client.

Workerman Service-side code:

use Workerman\Worker;require_once '../Workerman/Autoloader.php';$worker = new Worker('websocket://0.0.0.0:8484');$ws_worker->count = 4;$worker->onConnect = function($connection){echo "new connection from ip " . $connection->getRemoteIp() . "\n";};$worker->onMessage = function($connection, $data){var_dump($data);$connection->send('receive success');};$worker->onError = function($connection, $code, $msg){echo "error $code $msg\n";};$worker->onBufferFull = function($connection){echo "bufferFull and do not send again\n";};$worker->onBufferDrain = function($connection){echo "buffer drain and continue send\n";};$worker->onClose = function($connection){echo "connection closed\n";};$worker->onWorkerStop = function($worker){echo "Worker stopping...\n";};$worker->onWorkerStart = function($worker){echo "Worker starting...\n";};

Client code: Using the Socket.io, which is an Android app

private Socket mSocket;{    try {        mSocket = IO.socket("websocket://192.168.0.11:8484");    } catch (URISyntaxException e) {}}@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main_activity1);    mSocket.connect();    mSocket.emit("hello", "hello world");    mSocket.emit("emit something");    mSocket.send("send something");    mSocket.send("hello","thanks");}

Why does it occur when the connection just disconnects, and the information is not received. These are the information that the server receives.

new connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3connection closednew connection from ip 192.168.0.3

Https://github.com/walkor/phpsocket.io
There are PHP versions of Socket.io, which should also be based on Workerman.

Socket.io's client encapsulates its own protocol, not directly connected to workman?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.