flush on socks connection
This commit is contained in:
parent
799fffcb4a
commit
8578af2b2b
|
@ -14,23 +14,25 @@ public class SocksSocketFactory {
|
|||
|
||||
private static final byte[] LOCALHOST = new byte[]{127,0,0,1};
|
||||
|
||||
public static void createSocksConnection(Socket socket, String destination, int port) throws IOException {
|
||||
public static void createSocksConnection(final Socket socket, final String destination, final int port) throws IOException {
|
||||
final InputStream proxyIs = socket.getInputStream();
|
||||
final OutputStream proxyOs = socket.getOutputStream();
|
||||
proxyOs.write(new byte[]{0x05, 0x01, 0x00});
|
||||
byte[] response = new byte[2];
|
||||
proxyIs.read(response);
|
||||
if (response[0] != 0x05 || response[1] != 0x00) {
|
||||
proxyOs.flush();
|
||||
final byte[] handshake = new byte[2];
|
||||
proxyIs.read(handshake);
|
||||
if (handshake[0] != 0x05 || handshake[1] != 0x00) {
|
||||
throw new SocksConnectionException("Socks 5 handshake failed");
|
||||
}
|
||||
byte[] dest = destination.getBytes();
|
||||
final byte[] dest = destination.getBytes();
|
||||
final ByteBuffer request = ByteBuffer.allocate(7 + dest.length);
|
||||
request.put(new byte[]{0x05, 0x01, 0x00, 0x03});
|
||||
request.put((byte) dest.length);
|
||||
request.put(dest);
|
||||
request.putShort((short) port);
|
||||
proxyOs.write(request.array());
|
||||
response = new byte[7 + dest.length];
|
||||
proxyOs.flush();
|
||||
final byte[] response = new byte[7 + dest.length];
|
||||
proxyIs.read(response);
|
||||
if (response[1] != 0x00) {
|
||||
if (response[1] == 0x04) {
|
||||
|
|
Loading…
Reference in New Issue