Skip to Main Content
Websocket Essentials: Building apps with HTML5 websockets
book

Websocket Essentials: Building apps with HTML5 websockets

by Varun Chopra
May 2015
Intermediate to advanced content levelIntermediate to advanced
110 pages
2h 7m
English
Packt Publishing
Content preview from Websocket Essentials: Building apps with HTML5 websockets

The WebSockets client app

Let us start with writing client-side code in JavaScript. We will be hitting the same Echo server for now. Let's get started with our client-side code. Here is how the client code will look:

<!DOCTYPE html> <html> <head> <meta charset="utf-8" > <title>WebSocket Test</title> <script language="javascript" type="text/javascript"> var wsUri = "ws://echo.websocket.org/"; var output; function init(){ output = document.getElementById("output"); testWebSocket(); } function testWebSocket(){ websocket = new WebSocket(wsUri); websocket.onopen = onOpen; websocket.onclose = onClose; websocket.onmessage = onMessage; websocket.onerror = onError; } function onOpen(evt){ writeToScreen("CONNECTED"); doSend("WebSocket rocks"); } function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Definitive Guide to HTML5 WebSocket

The Definitive Guide to HTML5 WebSocket

Vanessa Wang, Frank Salim, Peter Moskovits

Publisher Resources

ISBN: 9781784396756Supplemental Content