diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-10-26 19:04:59 +0200 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-10-26 19:04:59 +0200 |
commit | ac865873239c8666e70cc3680f4168479dce8e1d (patch) | |
tree | 38715686a0a0ba33ab3c224b2968f8531a8c3813 | |
parent | e5cb9b1e17c6b25e937b2666fe2113fbdefffd89 (diff) |
flush on socks connection
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java b/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java index 266bb9d8c..2e060594b 100644 --- a/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java +++ b/src/main/java/de/pixart/messenger/utils/SocksSocketFactory.java @@ -12,23 +12,25 @@ import de.pixart.messenger.Config; public class SocksSocketFactory { - 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) { |