ioe.printStackTrace();
    private Response opensocket(Request request) throws UnknownHostException, IOException, SocketException  {        // We initialise all sockets to null;        _proxysocket = null;        _serversocket = null;        _sslsocket = null;        _in = null;        _out = null;                // We record where we are connected to, in case we might reuse this socket later        URL u = request.getURL();        _host = u.getHost();        _port = u.getPort()==-1?u.getDefaultPort():u.getPort();        boolean ssl = request.getURL().getProtocol().equalsIgnoreCase("https");                if (!ssl) {            // Check for a "noProxy" entry here            if (_httpProxy != null && !_httpProxy.equals("")) {                System.err.println("Connect to " + _httpProxy + ":" + _httpProxyPort);                _proxysocket = new Socket(_httpProxy, _httpProxyPort);                _proxysocket.setTcpNoDelay(true);                _proxysocket.setSoTimeout(60 * 1000);                _in = _proxysocket.getInputStream();                _out = _proxysocket.getOutputStream();            } else {                System.err.println("Connect to " + _host + ":" + _port );                _serversocket = new Socket(_host, _port);                _serversocket.setTcpNoDelay(true);                _serversocket.setSoTimeout(60 * 1000);                _in = _serversocket.getInputStream();                _out = _serversocket.getOutputStream();            }        } else {            // check for a noProxy entry here            if (_httpsProxy != null && !_httpsProxy.equals("")) {                // Send CONNECT, get OK, then we have a socket to the server                System.err.println("Connect to " + _httpsProxy + ":" + _httpsProxyPort);                _proxysocket = new Socket(_httpsProxy, _httpsProxyPort);                OutputStream proxyout = _proxysocket.getOutputStream();                InputStream proxyin = _proxysocket.getInputStream();                System.err.println("Proxy CONNECT to " + _host + ":" + _port);                proxyout.write(("CONNECT " + _host + ":" + _port + " HTTP/1.0\r\n").getBytes());                String proxyAuth = request.getHeader("Proxy-Authorization");                if (proxyAuth != null && !proxyAuth.equals("")) {                    proxyout.write(("Proxy-Authorization: " + proxyAuth + "\r\n").getBytes());                    request.deleteHeader("Proxy-Authorization");                }                proxyout.write("\r\n".getBytes());                proxyout.flush();                System.err.println("Sent CONNECT, reading Proxy response");                Response response = new Response();                response.read(proxyin);                System.err.println("Got response " + response.getStatusLine());                if (!response.getStatus().equals("200")) {                    return response;                }                System.err.println("HTTPS CONNECT successful");                _serversocket = _proxysocket;            } else {                _serversocket = new Socket(_host , _port);                _serversocket.setTcpNoDelay(true);                _serversocket.setSoTimeout(60 * 1000);            }                        if (_factory == null) {                initSSL();            }            // Use the factory to create a secure socket connected to the            // HTTPS port of the specified web server.            try {                _sslsocket=(SSLSocket)_factory.createSocket(_serversocket,_serversocket.getInetAddress().getHostName(),_serversocket.getPort(),true);                _sslsocket.setUseClientMode(true);            } catch (IOException ioe) {                System.err.println("Error layering SSL over the existing socket");                throw new SocketException("Error layering SSL over the socket " + ioe);            }            _in = _sslsocket.getInputStream();            _out = _sslsocket.getOutputStream();            System.err.println("Finished negotiating SSL");        }        if (_out == null || _in == null) {            return errorResponse(request, "Unknown error : in or out was null!");        }        return null;    }