Java Code Examples for java.net.SocketAddress#getClass()
The following examples show how to use
java.net.SocketAddress#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RouteSelector.java From bluemix-parking-meter with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 2
Source File: RouteSelector.java From crosswalk-cordova-android with Apache License 2.0 | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 3
Source File: RouteSelector.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 4
Source File: RouteSelector.java From wildfly-samples with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 5
Source File: RouteSelector.java From cordova-android-chromeview with Apache License 2.0 | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 6
Source File: RouteSelector.java From CordovaYoutubeVideoPlayer with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 7
Source File: RouteSelector.java From phonegapbootcampsite with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 8
Source File: RouteSelector.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 9
Source File: RouteSelector.java From reader with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 10
Source File: RouteSelector.java From reader with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 11
Source File: RouteSelector.java From android-discourse with Apache License 2.0 | 6 votes |
/** * Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException("Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 12
Source File: HTTPConnectSocket.java From marauroa with GNU General Public License v2.0 | 6 votes |
private void sendConnect(SocketAddress endpoint) throws IOException { if (!(endpoint instanceof InetSocketAddress)) { throw new IOException("Unkown endpoint object. Exspected InetSocketAddress but got " + endpoint.getClass()); } InetSocketAddress server = (InetSocketAddress) endpoint; /* CONNECT home.netscape.com:443 HTTP/1.0 User-agent: Mozilla/4.0 Proxy-authorization: basic dGVzdDp0ZXN0 */ OutputStream os = super.getOutputStream(); StringBuilder connect = new StringBuilder("CONNECT "); connect.append(server.getHostName()); connect.append(":"); connect.append(server.getPort()); connect.append(" HTTP/1.1\r\n"); connect.append("Accept: text/plain,text/html;q=0.9,*/*;q=0.5\r\n"); // TODO: add proxy authentication here connect.append("\r\n"); os.write(connect.toString().getBytes("UTF-8")); }
Example 13
Source File: RouteSelector.java From IoTgo_Android_App with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 14
Source File: RouteSelector.java From L.TileLayer.Cordova with MIT License | 6 votes |
/** Resets {@link #nextInetSocketAddress} to the first option. */ private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException { socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws! String socketHost; if (proxy.type() == Proxy.Type.DIRECT) { socketHost = uri.getHost(); socketPort = getEffectivePort(uri); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = proxySocketAddress.getHostName(); socketPort = proxySocketAddress.getPort(); } // Try each address for best behavior in mixed IPv4/IPv6 environments. socketAddresses = dns.getAllByName(socketHost); nextSocketAddressIndex = 0; }
Example 15
Source File: RouteSelector.java From styT with Apache License 2.0 | 5 votes |
/** Prepares the socket addresses to attempt for the current proxy or host. */ private void resetNextInetSocketAddress(Proxy proxy) throws IOException { // Clear the addresses. Necessary if getAllByName() below throws! inetSocketAddresses = new ArrayList<>(); String socketHost; int socketPort; if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) { socketHost = address.url().host(); socketPort = address.url().port(); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = getHostString(proxySocketAddress); socketPort = proxySocketAddress.getPort(); } if (socketPort < 1 || socketPort > 65535) { throw new SocketException("No route to " + socketHost + ":" + socketPort + "; port is out of range"); } if (proxy.type() == Proxy.Type.SOCKS) { inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost, socketPort)); } else { // Try each address for best behavior in mixed IPv4/IPv6 environments. List<InetAddress> addresses = address.dns().lookup(socketHost); for (int i = 0, size = addresses.size(); i < size; i++) { InetAddress inetAddress = addresses.get(i); inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort)); } } nextInetSocketAddressIndex = 0; }
Example 16
Source File: RouteSelector.java From AndroidProjects with MIT License | 5 votes |
/** Prepares the socket addresses to attempt for the current proxy or host. */ private void resetNextInetSocketAddress(Proxy proxy) throws IOException { // Clear the addresses. Necessary if getAllByName() below throws! inetSocketAddresses = new ArrayList<>(); String socketHost; int socketPort; if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) { socketHost = address.url().host(); socketPort = address.url().port(); } else { SocketAddress proxyAddress = proxy.address(); if (!(proxyAddress instanceof InetSocketAddress)) { throw new IllegalArgumentException( "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; socketHost = getHostString(proxySocketAddress); socketPort = proxySocketAddress.getPort(); } if (socketPort < 1 || socketPort > 65535) { throw new SocketException("No route to " + socketHost + ":" + socketPort + "; port is out of range"); } if (proxy.type() == Proxy.Type.SOCKS) { inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost, socketPort)); } else { // Try each address for best behavior in mixed IPv4/IPv6 environments. List<InetAddress> addresses = address.dns().lookup(socketHost); for (int i = 0, size = addresses.size(); i < size; i++) { InetAddress inetAddress = addresses.get(i); inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort)); } } nextInetSocketAddressIndex = 0; }
Example 17
Source File: AbstractIoConnector.java From neoscada with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public final void setDefaultRemoteAddress(SocketAddress defaultRemoteAddress) { if (defaultRemoteAddress == null) { throw new IllegalArgumentException("defaultRemoteAddress"); } if (!getTransportMetadata().getAddressType().isAssignableFrom(defaultRemoteAddress.getClass())) { throw new IllegalArgumentException("defaultRemoteAddress type: " + defaultRemoteAddress.getClass() + " (expected: " + getTransportMetadata().getAddressType() + ")"); } this.defaultRemoteAddress = defaultRemoteAddress; }
Example 18
Source File: NetUtils.java From big-c with Apache License 2.0 | 4 votes |
/** * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but * also takes a local address and port to bind the socket to. * * @param socket * @param endpoint the remote address * @param localAddr the local address to bind the socket to * @param timeout timeout in milliseconds */ public static void connect(Socket socket, SocketAddress endpoint, SocketAddress localAddr, int timeout) throws IOException { if (socket == null || endpoint == null || timeout < 0) { throw new IllegalArgumentException("Illegal argument for connect()"); } SocketChannel ch = socket.getChannel(); if (localAddr != null) { Class localClass = localAddr.getClass(); Class remoteClass = endpoint.getClass(); Preconditions.checkArgument(localClass.equals(remoteClass), "Local address %s must be of same family as remote address %s.", localAddr, endpoint); socket.bind(localAddr); } try { if (ch == null) { // let the default implementation handle it. socket.connect(endpoint, timeout); } else { SocketIOWithTimeout.connect(ch, endpoint, timeout); } } catch (SocketTimeoutException ste) { throw new ConnectTimeoutException(ste.getMessage()); } // There is a very rare case allowed by the TCP specification, such that // if we are trying to connect to an endpoint on the local machine, // and we end up choosing an ephemeral port equal to the destination port, // we will actually end up getting connected to ourself (ie any data we // send just comes right back). This is only possible if the target // daemon is down, so we'll treat it like connection refused. if (socket.getLocalPort() == socket.getPort() && socket.getLocalAddress().equals(socket.getInetAddress())) { LOG.info("Detected a loopback TCP socket, disconnecting it"); socket.close(); throw new ConnectException( "Localhost targeted connection resulted in a loopback. " + "No daemon is listening on the target port."); } }
Example 19
Source File: NetUtils.java From hadoop with Apache License 2.0 | 4 votes |
/** * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but * also takes a local address and port to bind the socket to. * * @param socket * @param endpoint the remote address * @param localAddr the local address to bind the socket to * @param timeout timeout in milliseconds */ public static void connect(Socket socket, SocketAddress endpoint, SocketAddress localAddr, int timeout) throws IOException { if (socket == null || endpoint == null || timeout < 0) { throw new IllegalArgumentException("Illegal argument for connect()"); } SocketChannel ch = socket.getChannel(); if (localAddr != null) { Class localClass = localAddr.getClass(); Class remoteClass = endpoint.getClass(); Preconditions.checkArgument(localClass.equals(remoteClass), "Local address %s must be of same family as remote address %s.", localAddr, endpoint); socket.bind(localAddr); } try { if (ch == null) { // let the default implementation handle it. socket.connect(endpoint, timeout); } else { SocketIOWithTimeout.connect(ch, endpoint, timeout); } } catch (SocketTimeoutException ste) { throw new ConnectTimeoutException(ste.getMessage()); } // There is a very rare case allowed by the TCP specification, such that // if we are trying to connect to an endpoint on the local machine, // and we end up choosing an ephemeral port equal to the destination port, // we will actually end up getting connected to ourself (ie any data we // send just comes right back). This is only possible if the target // daemon is down, so we'll treat it like connection refused. if (socket.getLocalPort() == socket.getPort() && socket.getLocalAddress().equals(socket.getInetAddress())) { LOG.info("Detected a loopback TCP socket, disconnecting it"); socket.close(); throw new ConnectException( "Localhost targeted connection resulted in a loopback. " + "No daemon is listening on the target port."); } }