/** Send a SOCKS V4 request. */ private void socksSendRequest(int command, InetAddress address, int port) throws IOException { Socks4Message request = new Socks4Message(); request.setCommandOrResult(command); request.setPort(port); request.setIP(address.getAddress()); request.setUserId("default"); // $NON-NLS-1$ getOutputStream().write(request.getBytes(), 0, request.getLength()); }
/** Read a SOCKS V4 reply. */ private Socks4Message socksReadReply() throws IOException { Socks4Message reply = new Socks4Message(); int bytesRead = 0; while (bytesRead < Socks4Message.REPLY_LENGTH) { int count = getInputStream() .read(reply.getBytes(), bytesRead, Socks4Message.REPLY_LENGTH - bytesRead); if (-1 == count) { break; } bytesRead += count; } if (Socks4Message.REPLY_LENGTH != bytesRead) { throw new SocketException(Msg.getString("KA011")); // $NON-NLS-1$ } return reply; }