doujiyan0971 2015-07-01 08:33
浏览 113

编写消息42 [“message”,“your message”]'编码为hybi10(或hybi13)并发送到websocket

Here is almost complete SOLUTION on stackoverflow to my problem

Problem is communication with my node JS server via PHP. I can't understand one detail in solution above:

compose message 42["message", "your message"]' to encode to hybi10 (or hybi13) and send to websocket

What does that mean? My node js server got "command" new message like this

  socket.on('new message', function (data) {
    socket.broadcast.emit('new message', {
      username: socket.username,
      message: data
    });
  });

Code from solution im using is:

$socketio = new SocketIO();
if ($socketio->send('localhost', 8080, 'message')){
    echo 'we sent the message and disconnected';
} else {
    echo 'Sorry, we have a mistake :\'(';
}

This code only connects to my server, but how to send "new message" message in correct format? Can't understand this 42["message", "your message"]'

  • 写回答

1条回答 默认 最新

  • douba6365 2016-12-30 10:04
    关注

    this is for php client side

    $socketio->send('localhost', 8080, 'add new message', 'this is my message');
    

    this is for server side

    // Socket receive "add new message" command    
    socket.on('add new message', function (messageText) {
        // print message
        console.log(messageText);
    
        // Broadcast to all clients.
        socket.broadcast.emit('add new message', {
            username: socket.username,
            message: messageText
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接