How to discover supported transport between browsers and server - Atmosphere/atmosphere Wiki

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.