Live data from Hacker News

How WebSockets work vs polling/long polling/streaming

websocket.org

31–40 of 44 posts

Re: How WebSockets work vs polling/long polling/streaming

#31
post #26

Earlier quoted context omitted.

Why? They are Web Sockets, and we have AJAX already.

Ajax is merely a client JS interface to HTTP. A protocol that already exist. It's not a protocol being imposed on web servers. When you want to impose a new protocol on web servers and browsers, it better not be to solve push notifications only. And that's what SPDY did.

WebSocket isn't just to solve push notifications. It's also for realtime communication, for example chat or multiplayer games. We do have server-sent updates if you just want push notifications.

Re: How WebSockets work vs polling/long polling/streaming

#32

Looks like an advertorial. No mention of socket.io and praise for a commercial solution that I didn't know after almost two years working with websockets.

Yup. It is an advertorial. Kaazing like promoting their own "WebSocket Gateway", and they're in a great position to, owning websocket.org By the way, at the moment I'm using Python's Twisted with a simple wrapper called txWS: https://github.com/MostAwesomeDude/txWS I'm not a big fan of socket.IO, seems too complex for my needs. I was quite happy to discover txWS, it's literally one more function call and you can just…

Shameless plug: SockJS is non-complex alternative to Socket.io, websockets polyfill.

Re: How WebSockets work vs polling/long polling/streaming

#33
post #9

I find it amusing that TCP was designed as and still is a full-duplex protocol for long-lived connections (streams). Then someone decides to use it in HTTP (1.0) for short-lived, half-duplex, message-oriented communication. Not surprisingly, it is not a good fit. Fast-forward a couple of years and everybody is busy de-crippling TCP in HTTP with various hacks trying to delay the HTTP request-response cycle, thus uncov…

Wait a little longer and, if we are very lucky, multicast will be "re-discovered" as well. That way, instead of having servers shove data down many sockets to many clients, they will write their payload down 1 multicast socket to all interested clients, with said payload crossing the network as little and as far as necessary but not more. So goes the wheel of progress...

[deleted]

Re: How WebSockets work vs polling/long polling/streaming

#34
post #32

Earlier quoted context omitted.

Yup. It is an advertorial. Kaazing like promoting their own "WebSocket Gateway", and they're in a great position to, owning websocket.org By the way, at the moment I'm using Python's Twisted with a simple wrapper called txWS: https://github.com/MostAwesomeDude/txWS I'm not a big fan of socket.IO, seems too complex for my needs. I was quite happy to discover txWS, it's literally one more function call and you can just…

Shameless plug: SockJS is non-complex alternative to Socket.io, websockets polyfill.

Added to WebSocket.us, thanks!

Re: How WebSockets work vs polling/long polling/streaming

#35
post #9

I find it amusing that TCP was designed as and still is a full-duplex protocol for long-lived connections (streams). Then someone decides to use it in HTTP (1.0) for short-lived, half-duplex, message-oriented communication. Not surprisingly, it is not a good fit. Fast-forward a couple of years and everybody is busy de-crippling TCP in HTTP with various hacks trying to delay the HTTP request-response cycle, thus uncov…

So what underlying protocol would you have used instead?

Re: How WebSockets work vs polling/long polling/streaming

#36

Earlier quoted context omitted.

Exactly. Ajax in general breaks REST, including bookmarking, caching, navigation and more. All major selling points of HTTP goes out the window. HTTP was created on top of TCP, but with severe restrictions to get the great features which HTTP is well-known for. Now someone re-lauches unrestricted TCP as a feature, when it is in fact much more simplistic and formed the base all along. Usage was purpously off limits du…

> Ajax in general breaks REST Huh? You are supposed to correctly choose the HTTP verbs and URI path precisely so that HTTP semantics apply. If you are talking about page state then there are numerous ways of dealing with that - one example is http://diveintohtml5.info/history.html If your assertion is that developers can write bad code, abuse HTTP semantics, defeat caches, break navigation etc then so what? With the…

I am saying that by using Ajax to partially update a page, that updated page no longer has a URL which identifies it. This breaks HATEOAS badly. The idea of REST is that every state on a site has a representation. REepresentational State Transfer you know... So while there are many other ways of shooting yourself in the foot when designing a REST website, using Ajax makes it almost inevitable.

Re: How WebSockets work vs polling/long polling/streaming

#37
post #9

I find it amusing that TCP was designed as and still is a full-duplex protocol for long-lived connections (streams). Then someone decides to use it in HTTP (1.0) for short-lived, half-duplex, message-oriented communication. Not surprisingly, it is not a good fit. Fast-forward a couple of years and everybody is busy de-crippling TCP in HTTP with various hacks trying to delay the HTTP request-response cycle, thus uncov…

So what underlying protocol would you have used instead?

Back then TCP was the best mainstream choice. Using UDP would have looked good due to its message orientation. But its limited message size, lack of re-ordering and congestion control would have disqualified it almost directly. TCP then looks better, since it has reliability, re-ordering and rate control. You only need to change the streaming functionality for senfing messages. This they did by using one TCP connection per message. What they missed, however, was that connections are expensive in TCP. There are a lot of handshakes and TCP probes a lot before opening the throttle, something you notice when downloading a big file. Throwing away connections like that is a waste. Ideally, you would want one connection per server and reuse it for multiple requests. This was done in HTTP 2.0, where connection:keep-alive was introduced. But TCP still has significant overhead and a slow rate control mechanism. It also does not allow multiple concurrent requests in the same connection. These problems are addressed by SCTP, which is really a great fit for HTTP and awesome in general. It is also message oriented. SPDY is another similar alternative, which is less general than SCTP.

But the point I was trying to make is that TCP was intentionally crippled by HTTP to acheive REST. Then people hack the restrictions of TCP and declare a new invention.

Re: How WebSockets work vs polling/long polling/streaming

#38

Earlier quoted context omitted.

I am not dismissing HTTP. The mistake I refered to was to limit TCP usage for www by only allowing the request-response oriented HTTP protocol. HTTP is opinionated and its REST-based architecture was explicitly chosen to disallow partial updates of web pages, thusly crippling TCP. But if one wants to build "thick client" type apps the restrictions of HTTP will weigh you down hard. Allowing for unrestricted TCP usage…

You say HTTP crippled TCP so as to not break-down REST. HTTP 1.0 does not seem to be designed for REST; it doesn't seem that REST was really published until quite a while later. Calling HTTP "REST-based" seems a bit of a stretch. On top of that, could you give a few examples of what you actually mean? Like what would a partial update be? TCP seems like a perfect fit for the underlying transport for a request/response…

Roy Fielding was involved in HTTP 1.0 and I believe that REST was a generalization of some of the principles used therein. I explained the breakdown in another comment, see http://news.ycombinator.com/item?id=4033717

Re: How WebSockets work vs polling/long polling/streaming

#39

Earlier quoted context omitted.

I am not dismissing HTTP. The mistake I refered to was to limit TCP usage for www by only allowing the request-response oriented HTTP protocol. HTTP is opinionated and its REST-based architecture was explicitly chosen to disallow partial updates of web pages, thusly crippling TCP. But if one wants to build "thick client" type apps the restrictions of HTTP will weigh you down hard. Allowing for unrestricted TCP usage…

You say HTTP crippled TCP so as to not break-down REST. HTTP 1.0 does not seem to be designed for REST; it doesn't seem that REST was really published until quite a while later. Calling HTTP "REST-based" seems a bit of a stretch. On top of that, could you give a few examples of what you actually mean? Like what would a partial update be? TCP seems like a perfect fit for the underlying transport for a request/response…

I'm not saying that TCP was a super-bad choice, just that they wanted only a subset of the features and got a bit more than they wanted. Also see http://news.ycombinator.com/item?id=4033822 .

Re: How WebSockets work vs polling/long polling/streaming

#40
post #9

I find it amusing that TCP was designed as and still is a full-duplex protocol for long-lived connections (streams). Then someone decides to use it in HTTP (1.0) for short-lived, half-duplex, message-oriented communication. Not surprisingly, it is not a good fit. Fast-forward a couple of years and everybody is busy de-crippling TCP in HTTP with various hacks trying to delay the HTTP request-response cycle, thus uncov…

Wait a little longer and, if we are very lucky, multicast will be "re-discovered" as well. That way, instead of having servers shove data down many sockets to many clients, they will write their payload down 1 multicast socket to all interested clients, with said payload crossing the network as little and as far as necessary but not more. So goes the wheel of progress...

Multicast is a nightmare over the general internet, from what I hear. It'd need some significant tooling to work properly.
Post reply on HN