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?