Provides networking support.
A NetworkDevice object can be constructed with TurbulenzEngine.createNetworkDevice.
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.
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));