News for hackers. Stuff that matters.
Re:You might not need a WebSocket by jkarneges on Thursday July 10, 2014 @12:23PM (#8015509)
Author here. For what reasons do HN folks choose WebSockets? Is it purely technical? Joining the bandwagon? Used by preferred frameworks? Would love to hear some opinions.
Re:You might not need a WebSocket by damon_c on Thursday July 10, 2014 @12:28PM (#8015532)
Conceptually, polling just seems dirty.

if (some event occurred){ do something over and over every so often that requires multitudes of processes including authentication, DNS etc. across many machines, that might not even ever return any value to the user. }

is not as nice as,

on('the arrival of a message', doSomething)

edit: pardon the sloppy pseudo syntax...

Re:You might not need a WebSocket by matt_kantor on Thursday July 10, 2014 @01:28PM (#8015921)
Why not server-sent events[0]?

    var source = new EventSource('/some/url/path');
    source.onmessage = doSomething;
[0] http://dev.w3.org/html5/eventsource/
Re:You might not need a WebSocket by YZF on Thursday July 10, 2014 @01:02PM (#8015761)
agreed but "long polling" is not really polling because you're blocking on the HTTP request. Something over UDP sounds like the answer to the complaints about TCP connections getting dropped though. TCP was built for streaming...
Re:You might not need a WebSocket by colanderman on Thursday July 10, 2014 @03:45PM (#8016779)
TCP technically relies only on state on the endpoints, so it "should" never be dropped unless the endpoints agree. But NAT and various other interlopers ruin this model, as state is then kept in middle-boxes.

UDP would evince the same problem when traversing NAT, since it also would require state to be kept in middle-boxes. The only difference is that instead of periodically reconnecting, you'd need to periodically ping.

Re:You might not need a WebSocket by drbawb on Thursday July 10, 2014 @12:52PM (#8015691)
Mostly technical, I need the performance, and my problem maps pretty well to raw sockets. The application I'm currently writing can push upwards of 60msgs/sec to the websocket client.

Using long-polling, etc. this just doesn't seem feasible. I'm sure my HTTP stack _could_ push small messages in <17msec fairly reliably... but that's not what it's built to do.

Tossing the request all the way down my HTTP stack just seems wasteful. There might be middleware hitting persistent caches, there might be a reverse proxy out in front, etc. -- This all takes non-negligible resources away from other requests, and this all takes time.

---

I should note that I do use SSE or long polling for things like event notifications. So in the end I fully agree with the article. WebSockets are not a tool that should be applied haphazardly. In my stack WebSocket upgrade requests hit an entirely different server, so I take great care in electing where to use them.

Re:You might not need a WebSocket by mey on Thursday July 10, 2014 @12:53PM (#8015697)
I don't use WebSockets mostly because of general lack of support and stability in the frameworks I use and clients I want to support. I typically use an in memory buffer server side of events generated to send down, the client polls (as rapidly as desired, sometimes on the minutes time frame, sometimes on the seconds) passing up the last package ID it received (or nothing if it's just starting up). The server from memory sends back all messages it has as the delta. This combined with keep-alive has worked rather well. I would not recommend this for mobile users or users who would be on metered connections, but the behavior of the client is easy to implement using ajax and throttling on the javascript side. By it's nature it automatically recovers from network drops or reroutes with no additional logic.
Re:You might not need a WebSocket by munro on Thursday July 10, 2014 @12:52PM (#8015692)
I used Socket.io for my site, so I don't care what the implementation. I just needed a way to push realtime events to the user.

Side note: Thinking about switching to SockJS since I use 1% of Socket.io features, but it's working well as is

Re:You might not need a WebSocket by jkrems on Thursday July 10, 2014 @02:53PM (#8016450)
For me it was just "the thing everyone was talking about". Was amazed when I discovered EventSource and puzzled why it wasn't more widely known. Axed the socket.io complexity immediately. Thanks for putting the word out about this!
Re:You might not need a WebSocket by thedufer on Thursday July 10, 2014 @04:47PM (#8017193)
I suspect we originally started using WebSockets because of the bandwagon, but it still feels like what we want. We use them to subscribe to various message feeds; client->server messages are used to add/remove subscriptions and server->client push messages that are on the subscribed feeds.

We have a small abstraction over the browser WebSocket object that gives auto-reconnect (and catches disconnects through polling frames) and an interface that looks more like a Node.js EventEmitter. We fall back to (normal) polling if the socket takes more than a few seconds to connect.