This week I started experimenting with WebSocket. The book I am using, WebSocket Essentials, left a lot to be desired. I found that the first examples were vague. The author uses the term, “It’s pretty straight forward” A LOT, even when it’s not. Regardless, here are my notes of the first half of the book and the exercises I did.
Begins with reviewing what we will and can use with websocket
- Offline Storage
- Drag & Drops
Discusses other methods for client server communication like:
- Request/Response: client makes a request, server response. Usually linked to a click or single action.
- Polling: Requests sent at intervals of time, regardless if data is undated. Repeating opening and closing connections
- Long Polling: A open connection for a set about of time. Real-time communication.
Great example of what the difference is: http://www.davesite.com/html5-code-tutorials/html5_interactive_intro_html_5/websockets/
Websockets and its API comes with HTML5. It is not supported by IE9 and earlier. It is implemented on both the client and the server. Server size needs a web sockets library implemented. Node.js can handle this. Web sockets can achieve real time communication. Because of this, it is mostly utilized in real time games web apps. Uses the TCP layer Ready States:
Exercise 1: Echo Test
Echo Test (http://www.websocket.org/echo.html). Send a message and server sends it back. Use Echo server to do it yourself.
Exercise 2: First Node.js Setup / WS
- Install Node.js with npm init
- Install Websockets package: npm install ws
- Run the node server with: node server.js
- Make sure URI is updated
Begins to get into real-time data transfer. Examples: Chat & online games
Exercise 3: Collaborative Web Presentation
Uses reveal.js to build this application and JS slides library (slides.com). Issue initializing node because reveal.js already has a package.json file. Slides in one window, when moved, move in the other window as well Okay, got the exercise to work. Rest of chapter was a list of this you can do, but not how to do them!
They rest of the book reviews:
- Creating a collaborative drawing application
- MVC review
- Mobile WebSocket Usage
I decided to skip to the mobile WebSocket example and work on that.
Since this book has left me wondering, I am going to swap it out for my own lesson plan. This will piece together individual tutorials. It will also have me digging through github repos and breakdown people’s code. The risk is that this code might not be the cleanest, but there is not that much approachable documentation on websocket just yet.
Next week I will have Websockets working on the iPhone & Desktop. It will be changing a color on both screens.
- WebSocket Essentials Reading / Exercises: 6hrs 45 mins
- External WebSocket Reading: 1 hr
- Presentation Prep: 1hr
- Revising Lesson Plans: 1 hrs 30 mins
- Total Time:10 hours 15 minutes