Search in sources :

Example 56 with InetSocketAddress

use of java.net.InetSocketAddress 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 57 with InetSocketAddress

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

the class PlainSocketImpl method accept.

@Override
protected void accept(SocketImpl newImpl) throws IOException {
    if (usingSocks()) {
        ((PlainSocketImpl) newImpl).socksBind();
        ((PlainSocketImpl) newImpl).socksAccept();
        return;
    }
    try {
        InetSocketAddress peerAddress = new InetSocketAddress();
        FileDescriptor clientFd = NetworkOs.accept(fd, peerAddress);
        // TODO: we can't just set newImpl.fd to clientFd because a nio SocketChannel may
        // be sharing the FileDescriptor. http://b//4452981.
        newImpl.fd.setInt$(clientFd.getInt$());
        newImpl.address = peerAddress.getAddress();
        newImpl.port = peerAddress.getPort();
    } catch (ErrnoException errnoException) {
        if (errnoException.errno == EAGAIN) {
            throw new SocketTimeoutException(errnoException);
        }
        throw new SocketException(errnoException.getMessage(), errnoException);
    }
    // Reset the client's inherited read timeout to the Java-specified default of 0.
    newImpl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(0));
    newImpl.localport = NetworkBridge.getSocketLocalPort(newImpl.fd);
}
Also used : SocketException(java.net.SocketException) ErrnoException(libcore.io.ErrnoException) SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) FileDescriptor(java.io.FileDescriptor)

Example 58 with InetSocketAddress

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

the class PlainSocketImpl method socksGetServerAddress.

/**
     * Gets the InetAddress of the SOCKS proxy server.
     */
private InetAddress socksGetServerAddress() throws UnknownHostException {
    String proxyName;
    // get socks server address from proxy. It is unnecessary to check
    // "socksProxyHost" property, since all proxy setting should be
    // determined by ProxySelector.
    InetSocketAddress addr = (InetSocketAddress) proxy.address();
    proxyName = addr.getHostName();
    if (proxyName == null) {
        proxyName = addr.getAddress().getHostAddress();
    }
    return InetAddress.getByName(proxyName);
}
Also used : InetSocketAddress(java.net.InetSocketAddress)

Example 59 with InetSocketAddress

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

the class DatagramChannelImpl method send.

@Override
public int send(ByteBuffer source, SocketAddress socketAddress) throws IOException {
    checkNotNull(source);
    checkOpen();
    InetSocketAddress isa = (InetSocketAddress) socketAddress;
    if (isa.getAddress() == null) {
        throw new IOException();
    }
    if (isConnected() && !connectAddress.equals(isa)) {
        throw new IllegalArgumentException("Connected to " + connectAddress + ", not " + socketAddress);
    }
    synchronized (writeLock) {
        int sendCount = 0;
        try {
            begin();
            int oldPosition = source.position();
            sendCount = NetworkBridge.sendto(fd, source, 0, isa.getAddress(), isa.getPort());
            if (sendCount > 0) {
                source.position(oldPosition + sendCount);
            }
            if (!isBound) {
                onBind(true);
            }
        } finally {
            end(sendCount >= 0);
        }
        return sendCount;
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 60 with InetSocketAddress

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

the class DatagramChannelImpl method onBind.

/**
     * Initialise the isBound, localAddress and localPort state from the file descriptor. Used when
     * some or all of the bound state has been left to the OS to decide, or when the Socket handled
     * bind() or connect().
     *
     * @param updateSocketState
     *        if the associated socket (if present) needs to be updated
     * @hide used to sync state, non-private to avoid synthetic method
     */
void onBind(boolean updateSocketState) {
    SocketAddress sa;
    try {
        sa = NetworkOs.getsockname(fd);
    } catch (ErrnoException errnoException) {
        throw new AssertionError(errnoException);
    }
    isBound = true;
    InetSocketAddress localSocketAddress = (InetSocketAddress) sa;
    localAddress = localSocketAddress.getAddress();
    localPort = localSocketAddress.getPort();
    if (updateSocketState && socket != null) {
        socket.onBind(localAddress, localPort);
    }
}
Also used : ErrnoException(libcore.io.ErrnoException) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2731 IOException (java.io.IOException)626 Test (org.junit.Test)614 Socket (java.net.Socket)362 InetAddress (java.net.InetAddress)253 ServerSocket (java.net.ServerSocket)182 SocketAddress (java.net.SocketAddress)180 ArrayList (java.util.ArrayList)179 Configuration (org.apache.hadoop.conf.Configuration)141 ByteBuffer (java.nio.ByteBuffer)135 UnknownHostException (java.net.UnknownHostException)127 InputStream (java.io.InputStream)106 SocketChannel (java.nio.channels.SocketChannel)106 OutputStream (java.io.OutputStream)104 SocketException (java.net.SocketException)94 File (java.io.File)93 URI (java.net.URI)80 HashMap (java.util.HashMap)79 Proxy (java.net.Proxy)72 ServerSocketChannel (java.nio.channels.ServerSocketChannel)69