Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Websocket Essentials: Building apps with HTML5 websockets

You're reading from  Websocket Essentials: Building apps with HTML5 websockets

Product type Book
Published in May 2015
Publisher
ISBN-13 9781784396756
Pages 110 pages
Edition 1st Edition
Languages
Author (1):
Varun Chopra Varun Chopra
Profile icon Varun Chopra

Tips and tricks


Let's talk about some tips and tricks that you can use while making an application.

  • Using JSON:

    The JSON format is an easily readable format in JavaScript. It is always good to transfer data in the JSON format.

  • Object-based structure for WebSockets:

    Normally, in any application where we have to transfer different data sets, it is always preferred that we finalize a proper structure for the messages. Take the example of a chatting application: if we finalize a structure, it is better to handle the message. Here is a sample structure:

      {
        type: "message"
        data : {
          from: "varun"
          to : "user1"
          data : "hello"
               }
      }
  • Using ArrayBuffer:

    There is another way to send data using ArrayBuffer; you can also send a Binary Large Object (BLOB). Here is an example of the same:

    var array = new Float32Array(5);
      for(var i = 0; i < array.length; ++i) {
        array[i] = i / 2;
      }
      ws.send(array, { binary: true, mask: true });

These kinds of structures can help in...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}