socket.io與workerman的問題

來源:互聯網
上載者:User
有誰玩過這兩個東西嗎?這兩個都能使用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吧?

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.