php websocket forwarding to nodejs

元气小坏坏 提交于 2019-12-13 04:25:38

问题


im tring to create an adapter in php to forward messages from javascript client to nodejs server and vice versa.

WebSockets:

nodejs server: ws

php server: RatchetPHP

php client: RatchetPawl

Code:

websocket server in php: chatWSServer.php

connection class: connection.php

javascript client:

connection = new WebSocket('ws://localhost:9000');
connection.onmessage = (e) => {
    console.log(e.data);
}
connection.onopen = (e) => {
    console.log("connection established!");
}
connection.addEventListener('message', (resData) => {
    console.log("got message:", resData);
});

Problem:

i try to open a connection to the nodejs websocket server (localhost:8889), on javscript client connection to php websocket server (localhost:9000): chatWSServer.php - createConnection() and its working, but when the javascript client try to send a message i get:

Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.

i think its because ratchet pawl connector loop is running - when i comment: loop->run() the client is able to send messages.


回答1:


with the help from @WyriHaximus i managed to solve this.

ive created a ratchetpawl websocket client with the same loop as ratchet websocket server's loop. and now its non blocking!

see my repository for code solution.



来源:https://stackoverflow.com/questions/52220769/php-websocket-forwarding-to-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!