Table Of Contents

Previous topic

17.7.1. The Vector2 Object

Next topic

17.9. The OcclusionQuery Object

This Page

17.8. The NetworkDevice Object

Provides networking support.

17.8.1. Constructor

A NetworkDevice object can be constructed with TurbulenzEngine.createNetworkDevice.

17.8.2. Methods

17.8.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.

17.8.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));