Saransh Mohapatra
Saransh Mohapatra

Reputation: 9636

Websocket App Design

Most examples I have seen are are just small demo's and not full stack applications and they use websocket for messaging, but for any chat application there is more data then just messages...suppose like user profile, his contacts etc.

So should I use websockets for all communication between server and client or just use them for sending messages and do other things through http? If I am to use websocket for all communication how do url design of the app...since websockets don't have have any different urls like http.

Upvotes: 0

Views: 174

Answers (2)

oberstet
oberstet

Reputation: 22051

You might be interested in WAMP, an officially registered WebSocket subprotocol that provides applications with WebSocket based

  • asynchronous, bidirectional remote procedure calls
  • real-time publish & subscribe notifications

Disclaimer: I am original author of WAMP and work for Tavendo.

Upvotes: 1

RMo
RMo

Reputation: 132

Pretty sure you'll get the usual "it depends" answer, because, well, it depends!

If you are going to build a large application, to be used by a number of different clients in different network arrangements etc then I personally wouldn't recommend using WebSockets for everything. Why?

  • It's a new standard, so not all clients support it
  • In some network configurations WebSocket traffic may be filtered out, meaning you end up with no communications - not great
  • If you end up exposing an external API then HTTP is much better fitted for the job and will likely be easier to code against. There are a lot more tools out there to help you with it and styles that everyone is familiar with, like REST, to follow.

Use WebSockets when you require data being pushed from the server without the client having to poll for it, or when HTTP header overhead becomes a problem. And if you still decide to use it make sure you have a fallback mechanism (e.g. longpolling) so you don't end up with no comms.

I'm afraid I can't help you regarding WebSocket API design... given it's a new standard I don't believe the community has settled on anything just yet so you'll have to come out with your own message-based scheme.

Upvotes: 0

Related Questions