Code example for Socket

Methods: getInputStream, setSoTimeout, setTcpNoDelay

0
            { 
                if (port == -1) 
                { 
                        port = 80;
                } 
                socket = new Socket(host, port);
            } 
            else if( scheme.equals("wss") )
            { 
                if (port == -1) {
                    port = 443;
                } 
                SocketFactory factory;
                if( trustAnyCertificate )
                { 
                    SSLContext context = SSLContext.getInstance( "TLS" );
                    context.init( null, new X509TrustManager[] { new X509TrustManager()
                    { 
                        public void checkClientTrusted( X509Certificate[] chain, String authType )
                            throws CertificateException 
                        { 
                        } 
 
                        public void checkServerTrusted( X509Certificate[] chain, String authType )
                            throws CertificateException 
                        { 
                        } 
 
                        public X509Certificate[] getAcceptedIssuers()
                        { 
                            return new X509Certificate[0];
                        } 
                    } }, null ); 
                     
                    factory = (SSLSocketFactory) context.getSocketFactory ();
                } 
                else 
                    factory = SSLSocketFactory.getDefault();
                 
                socket = factory.createSocket( host, port );
            } 
             
             
            socket.setTcpNoDelay( true );
 
            // workaround for android issu => close on socket doesnt throw ex.  
            socket.setSoTimeout( 5000 );
 
            input = socket.getInputStream();
         
            String handshake = "GET " + path + " HTTP/1.1\r\n" +
                                "Upgrade: WebSocket\r\n" + 
                                "Connection: Upgrade\r\n" + 
                                "Host: " + host + "\r\n" +