Web Sockets API
The BlackBerry® Browser now includes support for the Web Sockets API, which is designed to permit near real-time communication with web server. A web socket is a bi-directional communication channel between a web server and a browser that allows messages to be sent back and forth without requiring an HTTP request and response each time.
The Web Socket API is designed to hide much of the complexity of socket communication. A socket is opened when a WebSocket object is constructed. Once the socket connection is established, the browser and server can send data back and forth. Once the socket is closed, it cannot be reopened; a new WebSocket objected must be constructed.
Web sockets can be an efficient solution for a web applications that require regular communication with a server. Because a web socket is established once and used repeatedly without the need for communication over HTTP, it can greatly reduce the overhead of sending multiple HTTP headers back and forth. In addition, web sockets can eliminate the need for inefficient communication practices such as polling, in which the browser checks repeatedly for new data on the server. Because a web socket is an open communication channel, the browser only needs to listen for incoming messages. When the server has new data, it sends a new message to the browser. The browser receives the message as it arrives.
Web sockets are not subject to the same-origin policy. The browser can open a socket with a server that is different from the server that originally served the web page.
By default, support for web sockets is disabled in the BlackBerry Browser. To establish a web socket between the browser and a server, the user must first select the Enable Web Sockets setting in the BlackBerry Browser options. Because this technology is dependent upon a user setting, web developers should provide alternate content in the event that web sockets are not available.