Search in sources :

Example 51 with SocketAddress

use of java.net.SocketAddress in project robovm by robovm.

the class IoBridge method getSocketLocalAddress.

public static InetAddress getSocketLocalAddress(FileDescriptor fd) throws SocketException {
    try {
        SocketAddress sa = Libcore.os.getsockname(fd);
        InetSocketAddress isa = (InetSocketAddress) sa;
        return isa.getAddress();
    } catch (ErrnoException errnoException) {
        throw errnoException.rethrowAsSocketException();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 52 with SocketAddress

use of java.net.SocketAddress in project robovm by robovm.

the class RouteSelector method resetNextInetSocketAddress.

/** Resets {@link #nextInetSocketAddress} to the first option. */
private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException {
    // Clear the addresses. Necessary if getAllByName() below throws!
    socketAddresses = null;
    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;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 53 with SocketAddress

use of java.net.SocketAddress in project robovm by robovm.

the class SocketChannelTest method testCFII_UnsupportedType.

public void testCFII_UnsupportedType() throws Exception {
    class SubSocketAddress extends SocketAddress {

        private static final long serialVersionUID = 1L;

        //empty
        public SubSocketAddress() {
            super();
        }
    }
    statusNotConnected_NotPending();
    SocketAddress newTypeAddress = new SubSocketAddress();
    try {
        this.channel1.connect(newTypeAddress);
        fail("Should throw an UnsupportedAddressTypeException here.");
    } catch (UnsupportedAddressTypeException e) {
    // OK.
    }
}
Also used : UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 54 with SocketAddress

use of java.net.SocketAddress in project robovm by robovm.

the class SocketChannelTest method test_finishConnect.

/**
     * Regression test for Harmony-1947.
     */
public void test_finishConnect() throws Exception {
    SocketAddress address = new InetSocketAddress("localhost", 0);
    ServerSocketChannel theServerChannel = ServerSocketChannel.open();
    ServerSocket serversocket = theServerChannel.socket();
    serversocket.setReuseAddress(true);
    // Bind the socket
    serversocket.bind(address);
    boolean doneNonBlockingConnect = false;
    // Loop so that we make sure we're definitely testing finishConnect()
    while (!doneNonBlockingConnect) {
        channel1 = SocketChannel.open();
        // Set the SocketChannel to non-blocking so that connect(..) does
        // not block
        channel1.configureBlocking(false);
        boolean connected = channel1.connect(new InetSocketAddress("localhost", serversocket.getLocalPort()));
        if (!connected) {
            // Now set the SocketChannel back to blocking so that
            // finishConnect() blocks.
            channel1.configureBlocking(true);
            doneNonBlockingConnect = channel1.finishConnect();
        }
        if (doneNonBlockingConnect) {
            tryFinish();
        }
        channel1.close();
    }
    if (!serversocket.isClosed()) {
        serversocket.close();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerSocket(java.net.ServerSocket) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ServerSocketChannel(java.nio.channels.ServerSocketChannel)

Example 55 with SocketAddress

use of java.net.SocketAddress in project robovm by robovm.

the class OldSocketChannelTest method testOpenSocketAddress.

public void testOpenSocketAddress() throws IOException {
    this.channel1 = SocketChannel.open(localAddr1);
    assertTrue(this.channel1.isConnected());
    SocketAddress newTypeAddress = new SubSocketAddress();
    try {
        this.channel1 = SocketChannel.open(newTypeAddress);
        fail("Should throw UnexpectedAddressTypeException");
    } catch (UnsupportedAddressTypeException e) {
    // expected
    }
    SocketAddress unresolvedAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8080);
    try {
        this.channel1 = SocketChannel.open(unresolvedAddress);
        fail("Should throw UnresolvedAddressException");
    } catch (UnresolvedAddressException e) {
    // expected
    }
    SocketChannel channel1IP = null;
    try {
        channel1IP = SocketChannel.open(null);
        fail("Should throw an IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // correct
    }
    assertNull(channel1IP);
}
Also used : UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

SocketAddress (java.net.SocketAddress)355 InetSocketAddress (java.net.InetSocketAddress)279 IOException (java.io.IOException)79 Test (org.junit.Test)73 Socket (java.net.Socket)48 InetAddress (java.net.InetAddress)35 Channel (org.jboss.netty.channel.Channel)33 SocketException (java.net.SocketException)27 UnknownHostException (java.net.UnknownHostException)25 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)23 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)23 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)20 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)19 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)19 Proxy (java.net.Proxy)18 HashMap (java.util.HashMap)17 DatagramPacket (java.net.DatagramPacket)16 ByteBuffer (java.nio.ByteBuffer)16 Logger (org.apache.log4j.Logger)16 Test (org.testng.annotations.Test)16