package com.icecondor.eaglet.api;

import java.net.URI;
import java.net.URISyntaxException;

import com.koushikdutta.async.http.AsyncHttpClient;
import com.koushikdutta.async.http.AsyncHttpGet;
import com.koushikdutta.async.http.AsyncHttpRequest;

public class Client {

    private final URI apiUrl;
    private final AsyncHttpClient socket;

    public Client(String serverURL) throws URISyntaxException {
        apiUrl = new URI(serverURL);
        //socket = new TooTallSocket(apiUrl, new Dispatch());
        socket = AsyncHttpClient.getDefaultInstance();
    }

    public void connect() {
        // AndroidSync quirk, uses http urls
        String httpQuirkUrl = apiUrl.toString().replace("ws://", "http://").replace("wss://", "https://");
        AsyncHttpRequest get = new AsyncHttpGet(httpQuirkUrl);
        get.setTimeout(2500);
        socket.websocket(get, "my-protocol", new KoushiSocket(new Dispatch()));
    }


}

@@ -84,16 +84,358 @@
 ception;
+%0Aimport java.security.KeyManagementException;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.cert.CertificateException;%0Aimport java.security.cert.X509Certificate;%0A%0Aimport javax.net.ssl.SSLContext;%0Aimport javax.net.ssl.TrustManager;%0Aimport javax.net.ssl.X509TrustManager;%0A%0Aimport org.apache.http.conn.ssl.SSLSocketFactory;
 %0A%0Aimport
@@ -670,21 +670,21 @@
 pClient 
-socke
+clien
 t;%0A%0A    
@@ -850,21 +850,21 @@
         
-socke
+clien
 t = Asyn
@@ -897,16 +897,731 @@
 ance();%0A
+        try %7B%0A            SSLContext sslContext = SSLContext.getInstance(%22TLS%22);%0A            sslContext.init(null, new TrustManager%5B%5D %7B new NoTrustManager() %7D, null);%0A            client.getSSLSocketMiddleware().setSSLContext(sslContext);%0A            client.getSSLSocketMiddleware().setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);%0A            client.getSSLSocketMiddleware().setTrustManagers(new TrustManager%5B%5D%7Bnew NoTrustManager()%7D);%0A        %7D catch (NoSuchAlgorithmException e) %7B%0A            // TODO Auto-generated catch block%0A            e.printStackTrace();%0A        %7D catch (KeyManagementException e) %7B%0A            // TODO Auto-generated catch block%0A            e.printStackTrace();%0A        %7D%0A
     %7D%0A%0A 
@@ -1900,21 +1900,21 @@
         
-socke
+clien
 t.websoc
@@ -1926,64 +1926,580 @@
 et, 
-%22my-protocol%22, new KoushiSocket(new Dispatch()));%0A    %7D%0A
+null, new KoushiSocket(new Dispatch()));%0A        //com.koushikdutta.async.http.ConnectionClosedException) %7B%0A    %7D%0A%0A    private class NoTrustManager implements X509TrustManager %7B%0A        @Override%0A        public void checkClientTrusted(X509Certificate%5B%5D chain, String authType) throws CertificateException %7B%0A        %7D%0A%0A        @Override%0A        public void checkServerTrusted(X509Certificate%5B%5D chain, String authType) throws CertificateException %7B%0A        %7D%0A%0A        @Override%0A        public X509Certificate%5B%5D getAcceptedIssuers() %7B%0A            return null;%0A        %7D%0A    %7D
 %0A%0A%7D%0A

use SSL for encryption, not identifiation