/** * Handle a SOCKS4/SOCKS4a response from the proxy server. Test * the response buffer reply code and call {@link #setHandshakeComplete()} * if access is granted. * * @param buf the buffer holding the server response data. * @throws Exception if server response is malformed or if request is rejected * by the proxy server. */ protected void handleResponse(final IoBuffer buf) throws Exception { byte first = buf.get(0); if (first != 0) { throw new Exception("Socks response seems to be malformed"); } byte status = buf.get(1); // Consumes all the response data from the buffer buf.position(buf.position() + SocksProxyConstants.SOCKS_4_RESPONSE_SIZE); if (status == SocksProxyConstants.V4_REPLY_REQUEST_GRANTED) { setHandshakeComplete(); } else { throw new Exception("Proxy handshake failed - Code: 0x" + ByteUtilities.asHex(new byte[] { status }) + " (" + SocksProxyConstants.getReplyCodeAsString(status) + ")"); } } }
/** * Handle a SOCKS4/SOCKS4a response from the proxy server. Test * the response buffer reply code and call {@link #setHandshakeComplete()} * if access is granted. * * @param buf the buffer holding the server response data. * @throws Exception if server response is malformed or if request is rejected * by the proxy server. */ protected void handleResponse(final IoBuffer buf) throws Exception { byte first = buf.get(0); if (first != 0) { throw new Exception("Socks response seems to be malformed"); } byte status = buf.get(1); // Consumes all the response data from the buffer buf.position(buf.position() + SocksProxyConstants.SOCKS_4_RESPONSE_SIZE); if (status == SocksProxyConstants.V4_REPLY_REQUEST_GRANTED) { setHandshakeComplete(); } else { throw new Exception("Proxy handshake failed - Code: 0x" + ByteUtilities.asHex(new byte[] { status }) + " (" + SocksProxyConstants.getReplyCodeAsString(status) + ")"); } } }
/** * Handle a SOCKS4/SOCKS4a response from the proxy server. Test * the response buffer reply code and call {@link #setHandshakeComplete()} * if access is granted. * * @param buf the buffer holding the server response data. * @throws exception if server response is malformed or if request is rejected * by the proxy server. */ protected void handleResponse(final IoBuffer buf) throws Exception { byte first = buf.get(0); if (first != 0) { throw new Exception("Socks response seems to be malformed"); } byte status = buf.get(1); // Consumes all the response data from the buffer buf.position(buf.position() + SocksProxyConstants.SOCKS_4_RESPONSE_SIZE); if (status == SocksProxyConstants.V4_REPLY_REQUEST_GRANTED) { setHandshakeComplete(); } else { throw new Exception("Proxy handshake failed - Code: 0x" + ByteUtilities.asHex(new byte[] { status }) + " (" + SocksProxyConstants.getReplyCodeAsString(status) + ")"); } } }