0

javascript websocket send()

Hello, I am a newbie of websocket programming.
I have read and try the javascript websocket send(), it send a message to websocket server.
Can I call the server and get return value from server? or I must use the WAMP sub-protocol?

1 Answers1

1

WebSocket is low-level, point-to-point messaging. There is no such thing as "call a procedure on a server and get a result".

If you want to have such "remote procedure calling" (RPC), you need to layer something on top of WebSocket. WAMP provides that in an open standard protocol.

Of course you could also reinvent the wheel and implement your own RPC. But then you cannot reuse WAMP implementations like Rachet (currently WAMP v1 only) or Thruway (WAMP v2).

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • Thanks, Mr oberstet. I am still learning. If our team familiar with PHP only. And we want to write the server code(which has function let client "RPC" to) in PHP. Beside Rachet and Thruway, can we use the Crossbar.io. (PHP Server <--connect--> Crossbar <---connect--> javascript wamp client)? –  Aug 05 '14 at 08:57
  • Yes, exactly: you can write all your backend app code in PHP, and use AutobahnJS for browsers, wire up everything using Crossbar.io. But currently only Thruway is on WAMP2. So I'd recommend using that: http://crossbar.io/docs/Getting-started-with-PHP/ - code looks like this: https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/templates/hello/php/client.php – oberstet Aug 05 '14 at 09:21
  • Just to be sure: Crossbar and Thruway only supports WAMP2. Ratchet right now only WAMP1 - but they want to upgrade also. So you can't use Ratchet with Crossbar right now. – oberstet Aug 05 '14 at 09:22