Table Of Contents

Previous topic

9.29. The SoundFilter Object

Next topic

9.31. The WebSocket Object

This Page

9.30. The NetworkDevice Object

Provides networking support.

9.30.1. Constructor

A NetworkDevice object can be constructed with TurbulenzEngine.createNetworkDevice.

9.30.2. Methods

9.30.2.1. createWebSocket

Summary

Creates a WebSocket object that follows the browser standard.

Syntax

var websocket = networkDevice.createWebSocket("ws://isr2.mine.nu/echo");

websocket.onopen = function connectionOpened() {
    websocket.send("Hello World!");
};

websocket.onerror = function connectionError() {
    window.alert("Connection broken!");
    websocket.onopen = null;
    websocket.onerror = null;
    websocket.onclose = null;
    websocket.onmessage = null;
    websocket = null;
};

websocket.onmessage = function messageReceived(message) {
    window.alert("Message from server: " + message.data);
};

websocket.onclose = function connectionOpened() {
    window.alert("Connection closed!");
    websocket.onopen = null;
    websocket.onerror = null;
    websocket.onclose = null;
    websocket.onmessage = null;
    websocket = null;
};

Returns a WebSocket object.

9.30.2.2. update

Summary

Polls the state of all created WebSockets and calls the relevant callbacks: onopen, onmessage, onerror, onclose.

No messages will ever be received if this method is not called.

Note

This method should be called frequently to avoid network timeouts, for example once per rendering frame.

Syntax

function renderFrame()
{
    networkDevice.update();
}

TurbulenzEngine.setInterval(renderFrame, (1000 / 60));