4 ms·
This article didn't provide any more information than the title. Can anyone fill the rest of us in. What are WebSockets and why should I care?
by tieTYT 16y ago
This article didn't provide any more information than the title. Can anyone fill the rest of us in. What are WebSockets and why should I care?
- pjscott 16y agoThey're bidirectional sockets between the web browser and the server, essentially. They're handy whenever you want messages going back and forth between client and server without a bunch of reconnecting, or really ugly hacks. For example, apps like Etherpad or Apache Wave need to send messages for each editing operation (e.g. keystrokes), and it would really suck if they had to open a new HTTP connection for each one and do long-polling to receive from the server. Websockets make this sort of thing simply a matter of sending and receiving on a socket. Easy. You can fake them with something like Socket.IO, if you want the API and are willing to tolerate unpleasant performance on browsers that don't support it.
- tjarratt 16y agoWhat's the alternative for browsers that don't support it? If you want to gracefully degrade, then you may have to accept an underperforming solution. I'm using Socket.IO and while I'd rather not have to degrade to Flash for Firefox, if that's what I have to do to get support for Firefox users that haven't enabled websockets, I can live with it.
- mhitza 16y agoWebSockets are ugly hacks on their own. They use HTTP as well for the underlying channel of communication. The only difference is that with the WebSockets the ugliness is hidden from your daily programmer via a nice API.
- jimmyjazz14 16y agoThats not entirely true, Websockets do initiate over http (by using the 'Upgrade' header so they can share port 80 with normal http traffic) but after the initialization handshake is finished the traffic no longer uses the http protocol.
- mhitza 16y agoIndeed, I made a false assumption due to my lack of experience with WebSockets and sparse look I had over them. But I'll still going to stick with the fact that they are ugly hacks.
- deleted 16y ago[deleted]
- BarkMore 16y agoIt's a feature that the websocket upgrades from an HTTP connection. If your web server can support it, you can use your regular HTTP handler code to authenticate incoming requests and then upgrade to the websocket protocol. The API is not the only difference between HTTP and websockets. HTTP follows the request response pattern. A websocket is a pair of message streams.
- FooBarWidget 16y agoNo, WebSockets only use a protocol that looks like HTTP for the initial handshake.
- rdtsc 16y ago... then it is just an exchange of text frames delimited by 0x00 and 0xff bytes. People refer to it as "TCP for for the web", but it is more than that since it specifies framing as well.