有誰玩過這兩個東西嗎?這兩個都能使用websocket協議,
而且workerman伺服器的onConnect都已經執行了,說明用戶端和伺服器是能聯絡的。
但是為什麼剛一串連上馬上就斷開了呢?而且伺服器也沒有收到用戶端發送的資訊。
workerman服務端代碼:
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";};
用戶端代碼:用的是socket.io,這是一個android應用
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");}
為什麼會出現剛串連就斷開的情況呢,資訊也沒有收到。這面這些是伺服器收到的資訊。
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
回複內容:
有誰玩過這兩個東西嗎?這兩個都能使用websocket協議,
而且workerman伺服器的onConnect都已經執行了,說明用戶端和伺服器是能聯絡的。
但是為什麼剛一串連上馬上就斷開了呢?而且伺服器也沒有收到用戶端發送的資訊。
workerman服務端代碼:
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";};
用戶端代碼:用的是socket.io,這是一個android應用
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");}
為什麼會出現剛串連就斷開的情況呢,資訊也沒有收到。這面這些是伺服器收到的資訊。
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
這裡有php版本的socket.io,應該也是基於workerman做的
socket.io的用戶端封裝了自己的協議,不能直接連workman吧?