Provides a simple socket connection using WebSocket, or alternate communication mechanisms in legacy browsers for comet-style communication. This is based on the WebSocket API and returns an object that implements the WebSocket interface: http://dev.w3.org/html5/websockets/#websocket
Provides socket connections. This can be used with virtually any Comet protocol.
Parameter | Type | Description |
---|---|---|
argsOrUrl | Object | This uses the same arguments as the other I/O functions in Dojo, or a URL to connect to. The URL should be a relative URL in order to properly work with WebSockets (it can still be host relative, like //other-site.org/endpoint) |
An object that implements the WebSocket API
dojo.require("dojox.socket"); var socket = dojox.socket({"url://comet-server/comet"); // we could also add auto-reconnect support // now we can connect to standard HTML5 WebSocket-style events dojo.connect(socket, "onmessage", function(event){ var message = event.data; // do something with the message }); // send something socket.send("hi there"); whenDone(function(){ socket.close(); });
You can also use the Reconnect module:
dojo.require("dojox.socket"); dojo.require("dojox.socket.Reconnect"); var socket = dojox.socket({url:"/comet"}); // add auto-reconnect support socket = dojox.socket.Reconnect(socket);
Provides a simple long-poll based comet-style socket/connection to a server and returns an object implementing the WebSocket interface: http://dev.w3.org/html5/websockets/#websocket
Parameter | Type | Description |
---|---|---|
args | Object | This uses the same arguments as the other I/O functions in Dojo, with this addition: args.interval: Indicates the amount of time (in milliseconds) after a response was received before another request is made. By default, a request is made immediately after getting a response. The interval can be increased to reduce load on the server or to do simple time-based polling where the server always responds immediately. args.transport: Provide an alternate transport like dojo.io.script.get |
An object that implements the WebSocket API
dojo.require("dojox.socket.LongPoll"); var socket = dojox.socket.LongPoll({url:"/comet"});
or:
dojo.require("dojox.socket.LongPoll"); dojox.socket.LongPoll.add(); var socket = dojox.socket({url:"/comet"});
Parameter | Type | Description |
---|---|---|
socket | undefined | |
newSocket | undefined | |
listenForOpen | undefined |
A wrapper for WebSocket, than handles standard args and relative URLs
Parameter | Type | Description |
---|---|---|
args | undefined | |
fallback | undefined |