News for hackers. Stuff that matters.
Re:A WebSocket Primer by pornel on Monday December 16, 2013 @03:57PM (#6917761)
It's funny that the article says "This enables server sent events" without actually referring to the HTML5 Server Sent Events API:

http://www.html5rocks.com/en/tutorials/eventsource/basics/

SSE is realtime server->client protocol that's fully compatible with HTTP and has lower handshake overhead (no Upgrade roundtrip, doesn't require HTTPS to go through proxies).

Re:A WebSocket Primer by rch on Monday December 16, 2013 @04:29PM (#6917937)
Agreed. Both approaches have their place, but I see SSE getting overlooked too often.
Re:A WebSocket Primer by yogo on Monday December 16, 2013 @06:11PM (#6918503)
I'm not 100% up to speed on SSE but since there is no way to "push" to a client isn't it just some form of polling at the end of the day?

It's also not supported by IE yet: http://caniuse.com/eventsource

Compare with http://caniuse.com/websockets

Re:A WebSocket Primer by dspillett on Tuesday December 17, 2013 @05:25AM (#6920388)
> isn't it just some form of polling at the end of the day?

Probably long-poll, a single connection from client to server kept alive with the occasional byte sent one way which sends the message and disconnects when there is something to send (the disconnect, requiring a new request from the client is because some clients won't process what has been sent immediately unless the connection is closed).

I once wrote a messaging client that operated this way. It is efficient in terms of bandwidth use and client footprint, though if you are using a process based we server it can be quite inefficient there (an event driven service on few processes/threads is far more efficient for handling many long-lived low-activity connections).

Re:A WebSocket Primer by rch on Monday December 16, 2013 @06:39PM (#6918670)
That's in keeping with how I think of it: open connection from the client with some reasonable expectations set around e.g. reconnection behavior.

Looks like Chrome and Firefox have had support for quite some time. I'm alright with that.

Re:A WebSocket Primer by sampk on Tuesday December 17, 2013 @01:30AM (#6919867)
IE is just trying to look all hip and cool and EventSource hasn't generated much hype so it doesn't get implemented.. shame.
Re:A WebSocket Primer by lostcolony on Monday December 16, 2013 @10:49PM (#6919508)
Do SSEs now support CORS? I know when writing a webapp at the start of this year we went with Websockets because we needed to work in a cross domain environment and SSEs didn't support it; I know it was to be added to the standard, and Firefox had unofficial support of it, but I can't find anything anywhere indicating if Chrome and Safari are supporting it (and IE will probably get it in 12 eyeroll).
Re:A WebSocket Primer by jessaustin on Monday December 16, 2013 @04:43PM (#6918034)
Thanks for the pointer! This seems much more straightforward than websockets.
Re:A WebSocket Primer by shubber on Monday December 16, 2013 @03:09PM (#6917454)
Related: definitely check out https://github.com/sockjs
Re:A WebSocket Primer by TheMakeA on Monday December 16, 2013 @04:51PM (#6918077)
Also check out https://github.com/primus/primus It's an abstraction layer over sockjs, socket.io, etc.
Re:A WebSocket Primer by jdp23 on Monday December 16, 2013 @04:55PM (#6918111)
Does any have experiences with Primus they can share?

The idea of being able to insulate the rest of the code from the specifics of which lower-level library I'm using is very attractive. On the other hand, any abstraction layer can introduce bugs in its own right. Thoughts about the tradeoff?

Re:A WebSocket Primer by corford on Monday December 16, 2013 @05:30PM (#6918303)
I'm using it now for a project that's due to go live early next year and so far it's been a dream. Case in point, I ran in to a bug on Monday and it turned out to be with engine.io itself rather than Primus. The workaround was a one line code change swapping the transformer to something else.

Arnout Kazemier (the lead dev) is a really nice guy and when I pinged him about the egine.io bug, he pushed out a change to Primus 24 hours later that worked around the bug and let me continue to use engine.io as the transformer.

YMMV but so far I've no regrets using it.

Re:A WebSocket Primer by TheMakeA on Monday December 16, 2013 @05:15PM (#6918224)
I was using socket.io until about two weeks ago when I ran into some reconnecting issues that weren't fixed. I decided to use Primus + Multiplex + Emitter. I have only run into one issue so far with Multiplex on IE10, but that was fixed quickly. Otherwise the package seems rather solid.
Re:A WebSocket Primer by general_failure on Monday December 16, 2013 @07:39PM (#6918944)
Does anyone know the purpose of Sec-WebSocket-Key and the associated Accept? I know the hashing stuff (https://en.wikipedia.org/wiki/WebSocket) but I don't understand why it exists.
Re:A WebSocket Primer by tec27 on Tuesday December 17, 2013 @02:33AM (#6919998)
It's there to help guarantee that the server the browser is connecting to actually understands websockets and isn't being "tricked" into opening a connection through clever request formulation. With that guarantee in place, browsers can trust servers to properly check for and limit cross-domain requests and the like and not need to use something like CORS to negotiate that stuff.
Re:A WebSocket Primer by general_failure on Tuesday December 17, 2013 @10:38AM (#6921653)
Why not skip all the hashing stuff? Why not just have Sec-Key: 'secret' and expect a reply with Sec-Accept: 'secret'. (where secret is hardcoded constant)
Re:A WebSocket Primer by moron4hire on Monday December 16, 2013 @09:34PM (#6919256)
I've actually been writing a MUD in Node.js with WebSockets (well, Socket.IO, thus I get failover support). It's been a lot of fun, and has been really easy to use.

What is really interesting is just how easy it is to use WebSockets with the latest libraries. I've got a project in .NET that relies on a lot of Microsoft-specific libraries right now. But with the ease of WebSockets, I can rewrite the UI in HTML5 like we always wanted and get around to rewriting the MS-specific stuff in Java or Python more likely whenever I feel like it.

It's like completely platform agnostic pipes, in a way that TCP/IP sockets never seemed to quite do.

EDIT: I think it's just that I don't have to listen for new connections and figure out how to bind them in a loop that I keep alive myself. I get an event when users connect.

Re:A WebSocket Primer by tibbon on Monday December 16, 2013 @07:55PM (#6918991)
Found out today that WebSockets now work on Heroku. Wrote a little quick app that uses them: http://colorchats.herokuapp.com/

Need to clean up a few things, but it was a neat 45 minutes.

Re:A WebSocket Primer by warfangle on Monday December 16, 2013 @06:46PM (#6918710)
Would have rather seen sample code as Plain Old Javascript, or some other language that you can use without buying into the Microsoft ecosystem.

Suggest the title be changed to:

A WebSocket Primer for .Net 4.5

The rest of it is a cool read, though. Thanks for submitting.

Re:A WebSocket Primer by brudgers on Monday December 16, 2013 @09:03PM (#6919172)
Maybe C# was just the language at hand when the research was done, perhaps as part of a day job. Why not blog something up about web sockets in JavaScript?
Re:A WebSocket Primer by gwu78 on Tuesday December 17, 2013 @12:00AM (#6919693)
Is there a commandline http client that can negotiate WebSockets? If so, I might be tempted to experiment.
Re:A WebSocket Primer by tlb on Tuesday December 17, 2013 @03:32AM (#6920121)
Libwebsockets contains a simple command line client and server:

http://libwebsockets.org/

Re:A WebSocket Primer by firen on Monday December 16, 2013 @03:47PM (#6917703)
Great explanation!