JS/HTML5 WebSocket: Connect without HTTP call
No. Once the connection is established you have a true socket. But you're right that it requires special server support. So it won't let you connect to an unmodified POP or IMAP server.
They chose that design (the Upgrade mechanism) so you could easily have a server that listened for WebSocket connections as well as true HTTP requests.
There is still a big distinction from AJAX and COMET. You can use WebSockets to have true full-duplex communication between server and client. Previous browser APIs haven't provided that, forcing people to use various work-arounds (such as repeated AJAX requests, COMET's forever frame, and others).
Related videos on Youtube
Qix - MONICA WAS MISTREATED
"I eat celery at 7 degrees." - This bird "Every programmer is developing in [a] group of programmers. The smallest group is yourself, and [your future self]." - Michael Suodenjoki "I'm pragmatic, not dogmatic." - Jon Skeet
Updated on May 14, 2022Comments
-
Qix - MONICA WAS MISTREATED about 2 years
Alright so I just tried out the new WebSocket class in HTML 5, and was pretty excited they exist; however, I fail to see how they are much more rewarding than AJAX seeing as how they still initiate an HTTP call and are not like conventional sockets. That's why I'm asking here.
Is there a way with HTML 5's
WebSocket
class to connect to a listening socket without sending HTTP data? Currently with TCP/IP builder it's showing all this header crap that I don't want (since I want to connect to POP3/IMAP servers without things like Flash bridges or Comet).Possible?
Output from connection:
Listening for connections...Connected GET / HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: localhost:666 Origin: null Sec-WebSocket-Key1: 2 987_390VNw60yi9 Sec-WebSocket-Key2: ~196 Y p 5 P67 428 ?
-
Qix - MONICA WAS MISTREATED over 13 yearsSo it's pretty much AJAX that doesn't close? Kind of like a forever-frame combined with AJAX. Nifty, but not so nifty at the same time. Thank you for the information!
-
kanaka over 13 yearsit's not quite a pure TCP socket after the handshake because there is additional framing for each frame. @Di-0xide, it's really more like a socket with a HTTP-like handshake (and some minimal framing). The handshake makes it easier to add WebSockets support to web servers and proxies, but that's all. It's not an HTTP request, it's a WebSockets handshake that just looks like HTTP.
-
Matthew Flaschen over 13 years@kanaka, I didn't mean to imply it was a TCP socket. There are many other kinds (UDP, raw, domain, etc.). WebSocket is yet another.
-
kanaka over 13 yearstechnically a WebSocket connection uses TCP sockets :-). But it's not a pure/raw TCP socket. TCP, UDP, etc are OSI layer 4 (transport). WebSockets are more in OSI layer 5 and 6. In theory you could have WebSocket connections over UDP (or domain socket, etc) but the current WebSockets definition is layered on TCP.
-
Matthew Flaschen over 13 years@kanaka, I didn't say it was a raw TCP socket, just that it was a socket (implemented over TCP).
-
Frank almost 12 yearsAre there any Imap servers that support websockets yet? Is there a way to make dovecot work with websockets?
-
Qix - MONICA WAS MISTREATED over 11 years@Frank not that I have seen thus far.