diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils')
-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) { |