0

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"]'

Community
  • 1
  • 1
John
  • 49
  • 1
  • 6
  • Result is in Array message is Key & Your Message is it's value. – test Jul 01 '15 at 08:36
  • i tried $arr = array('new message', 'myrealmessage'); $socketio = new SocketIO(); if ($socketio->send('localhost', 8080, $arr)){... but its not working :/ – John Jul 01 '15 at 09:00

1 Answers1

2

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
    });
});
husmen73
  • 97
  • 1
  • 9