Skip to content

How to discover supported transport between browsers and server

jfarcand edited this page Jun 27, 2012 · 1 revision

How to discover supported transport between browsers and server

The following code describes how to discover what the browser and server supports. On the client side:

    var transports = new Array();
    transports[0] = "websocket";
    transports[1] = "sse";
    transports[2] = "jsonp";
    transports[3] = "long-polling";
    transports[4] = "streaming";
    transports[5] = "ajax";

    $.each(transports, function (index, transport) {
        var req = new $.atmosphere.AtmosphereRequest();

        req.url = document.location.toString() + 'chat';
        req.contentType = "application/json";
        req.transport = transport;
        req.headers = { "negotiating" : "true" };

        req.onOpen = function(response) {
            detect.append('<p><span style="color:blue">' + transport 
                + ' supported: '  + '</span>' + (response.transport == transport));
        }

        req.onReconnect = function(request) {
            request.close();
        }
        socket.subscribe(req)
    });

On the server side,

public class DetectAtmosphereHandler implements AtmosphereHandler {
    @Override
    public void onRequest(AtmosphereResource r) throws IOException {
        r.getResponse().getWriter().write("OK");    
    }

Download the atmosphere-chat to demo live.

Step by Step Tutorials

Concepts & Architecture

15 Minutes Tutorial

Advanced Topics

API

Known WebServer Issues

References

External Documentations

githalytics.com alpha

Clone this wiki locally