dongwen7371 2018-09-07 10:38
浏览 138

php websocket转发到nodejs

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条回答 默认 最新

  • douyou2732 2018-09-07 11:41
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题