Search in sources :

Example 46 with InetAddress

use of java.net.InetAddress in project j2objc by google.

the class SocketChannelImpl method finishConnect.

@Override
public boolean finishConnect() throws IOException {
    synchronized (this) {
        if (!isOpen()) {
            throw new ClosedChannelException();
        }
        if (status == SOCKET_STATUS_CONNECTED) {
            return true;
        }
        if (status != SOCKET_STATUS_PENDING) {
            throw new NoConnectionPendingException();
        }
    }
    boolean finished = false;
    try {
        begin();
        InetAddress inetAddress = connectAddress.getAddress();
        int port = connectAddress.getPort();
        // Return immediately.
        finished = NetworkBridge.isConnected(fd, inetAddress, port, 0, 0);
    } catch (ConnectException e) {
        if (isOpen()) {
            close();
            finished = true;
        }
        throw e;
    } finally {
        end(finished);
    }
    synchronized (this) {
        status = (finished ? SOCKET_STATUS_CONNECTED : status);
        if (finished && socket != null) {
            socket.onConnect(connectAddress.getAddress(), connectAddress.getPort());
        }
    }
    return finished;
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) NoConnectionPendingException(java.nio.channels.NoConnectionPendingException) InetAddress(java.net.InetAddress) ConnectException(java.net.ConnectException)

Example 47 with InetAddress

use of java.net.InetAddress in project j2objc by google.

the class PlainDatagramSocketImpl method send.

@Override
public void send(DatagramPacket packet) throws IOException {
    int port = isNativeConnected ? 0 : packet.getPort();
    InetAddress address = isNativeConnected ? null : packet.getAddress();
    NetworkBridge.sendto(fd, packet.getData(), packet.getOffset(), packet.getLength(), 0, address, port);
}
Also used : InetAddress(java.net.InetAddress)

Example 48 with InetAddress

use of java.net.InetAddress in project j2objc by google.

the class PlainDatagramSocketImpl method joinGroup.

@Override
public void joinGroup(SocketAddress addr, NetworkInterface netInterface) throws IOException {
    if (addr instanceof InetSocketAddress) {
        InetAddress groupAddr = ((InetSocketAddress) addr).getAddress();
        setOption(NetworkBridge.JAVA_MCAST_JOIN_GROUP, makeGroupReq(groupAddr, netInterface));
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress)

Example 49 with InetAddress

use of java.net.InetAddress in project j2objc by google.

the class PlainSocketImpl method connect.

/**
     * Connects this socket to the specified remote host address/port.
     *
     * @param anAddr
     *            the remote host address to connect to
     * @param aPort
     *            the remote port to connect to
     * @param timeout
     *            a timeout where supported. 0 means no timeout
     * @throws IOException
     *             if an error occurs while connecting
     */
private void connect(InetAddress anAddr, int aPort, int timeout) throws IOException {
    InetAddress normalAddr = anAddr.isAnyLocalAddress() ? InetAddress.getLocalHost() : anAddr;
    if (streaming && usingSocks()) {
        socksConnect(anAddr, aPort, 0);
    } else {
        NetworkBridge.connect(fd, normalAddr, aPort, timeout);
    }
    super.address = normalAddr;
    super.port = aPort;
}
Also used : InetAddress(java.net.InetAddress)

Example 50 with InetAddress

use of java.net.InetAddress in project j2objc by google.

the class DatagramChannelImpl method connect.

@Override
public synchronized DatagramChannel connect(SocketAddress address) throws IOException {
    // must be open
    checkOpen();
    // status must be un-connected.
    if (connected) {
        throw new IllegalStateException();
    }
    // check the address
    InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address);
    InetAddress remoteAddress = inetSocketAddress.getAddress();
    int remotePort = inetSocketAddress.getPort();
    try {
        begin();
        NetworkBridge.connect(fd, remoteAddress, remotePort);
    } catch (ConnectException e) {
    // ConnectException means connect fail, not exception
    } finally {
        end(true);
    }
    // address state held by the channel and the socket up to date.
    if (!isBound) {
        onBind(true);
    }
    // Keep the connected state held by the channel and the socket up to date.
    onConnect(remoteAddress, remotePort, true);
    return this;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) ConnectException(java.net.ConnectException)

Aggregations

InetAddress (java.net.InetAddress)2225 UnknownHostException (java.net.UnknownHostException)423 IOException (java.io.IOException)295 Test (org.junit.Test)289 InetSocketAddress (java.net.InetSocketAddress)251 NetworkInterface (java.net.NetworkInterface)192 ArrayList (java.util.ArrayList)174 SocketException (java.net.SocketException)154 HashMap (java.util.HashMap)104 Inet6Address (java.net.Inet6Address)103 Inet4Address (java.net.Inet4Address)96 Socket (java.net.Socket)78 DatagramPacket (java.net.DatagramPacket)75 LinkAddress (android.net.LinkAddress)70 DatagramSocket (java.net.DatagramSocket)67 Token (org.apache.cassandra.dht.Token)67 Map (java.util.Map)59 RouteInfo (android.net.RouteInfo)56 LinkProperties (android.net.LinkProperties)52 ServerSocket (java.net.ServerSocket)52