HTML and CSS Reference
In-Depth Information
Chapter 4. Data
Receiving, and Decoding
Modern web development is all about content. No matter what kind of application you
are building, users will stop using it unless they get what they want. In the old days
of the web, the content someone could publish on his/her website was extremely lim-
ited. Nowadays, content is a lot more than static text and images; you can exchange
messages, watch videos, download programs, and much more. As a web developer,
you should be able to deliver the desired content in a fast and efficient way. The We-
bSocket protocol supports a variety of transferable data, taking the burden to speed
the whole process as much as possible.
In this chapter's demo, you are going to handle image and video data via WebSock-
ets. Let's start!
What kinds of data can WebSockets
The WebSocket protocol supports text and binary data. In JavaScript, text is referred
to as String, while binary data is represented by the ArrayBuffer and Blob classes (the
first one is still experimental). Using plain text and binary format, you can transfer and
decode almost any type of HTML5 media.
Always keep in your mind that WebSockets only support one binary format at a time
and you have to explicitly declare it as follows:
socket.binaryType = "arraybuffer";
Another was to do it is as follows:
socket.binaryType = "blob"
Throughout this topic, we'll demonstrate specific examples for using each and every
data type.
Search WWH ::

Custom Search