HTML and CSS Reference
In-Depth Information
Dropping an image to the browser and sending it to the server
Receiving data as ArrayBuffers is fairly simple. Note that you check using in-
stanceof , rather than the strict equal operator.
socket.onmessage = function(event) {
if (event.data instanceof ArrayBuffer) {
var buffer = event.data;
}
}
Blobs
Blobs ( Binary Large Objects ) contain totally raw data in their most native form. A
blob might theoretically be anything, even a non-JavaScript object. As a result, in-
terpreting blob data might be quite tricky. As a thumb rule, you'd better know exactly
what the server is supposed to send, otherwise you'll need to make fairly non-con-
crete assumptions.
However, the big advantage of blob data is their file size. Binary format is machine-
level format, so there are almost no abstraction layers used that would increase its
size.
When you transmit multimedia over the web, you need the highest speed possible,
in order to achieve the best user experience. The WebSocket blobs do not create
extra burden for your Internet connection and they rely on the client for proper inter-
pretation.
Following code shows how you can display an incoming image, sent as a set of raw
bits:
socket.onmessage = function(event) {
if (event.data instanceof Blob) {
// 1. Get the raw data.
var blob = event.data;
// 2. Create a new URL for the blob object.
Search WWH ::




Custom Search