Search in sources :

Example 31 with SocketAddress

use of java.net.SocketAddress in project jackrabbit-oak by apache.

the class ClientFilterHandlerTest method disallowedClientsShouldNotBeServed.

@Test
public void disallowedClientsShouldNotBeServed() {
    EmbeddedChannel channel = new EmbeddedChannel(new ClientFilterHandler(new ClientFilter() {

        @Override
        public boolean isAllowed(SocketAddress address) {
            return false;
        }
    }));
    channel.connect(new InetSocketAddress("127.0.0.2", 8080));
    assertFalse(channel.isOpen());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 32 with SocketAddress

use of java.net.SocketAddress in project geode by apache.

the class ServerHandShakeProcessor method readClientVersion.

private static Version readClientVersion(ServerConnection connection) throws IOException, VersionException {
    Socket socket = connection.getSocket();
    int timeout = connection.getHandShakeTimeout();
    int soTimeout = -1;
    try {
        soTimeout = socket.getSoTimeout();
        socket.setSoTimeout(timeout);
        InputStream is = socket.getInputStream();
        short clientVersionOrdinal = Version.readOrdinalFromInputStream(is);
        if (clientVersionOrdinal == -1) {
            throw new EOFException(LocalizedStrings.ServerHandShakeProcessor_HANDSHAKEREADER_EOF_REACHED_BEFORE_CLIENT_VERSION_COULD_BE_READ.toLocalizedString());
        }
        Version clientVersion = null;
        try {
            clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
        } catch (UnsupportedVersionException uve) {
            // Allows higher version of wan site to connect to server
            if (connection.getCommunicationMode() == Acceptor.GATEWAY_TO_GATEWAY && !(clientVersionOrdinal == Version.NOT_SUPPORTED_ORDINAL)) {
                return Acceptor.VERSION;
            } else {
                SocketAddress sa = socket.getRemoteSocketAddress();
                String sInfo = "";
                if (sa != null) {
                    sInfo = " Client: " + sa.toString() + ".";
                }
                throw new UnsupportedVersionException(uve.getMessage() + sInfo);
            }
        }
        if (!clientVersion.compatibleWith(Acceptor.VERSION)) {
            // we can throw this
            throw new IncompatibleVersionException(clientVersion, Acceptor.VERSION);
        // to restrict
        }
        // Backward Compatibilty Support to limited no of versions
        return clientVersion;
    } finally {
        if (soTimeout != -1) {
            try {
                socket.setSoTimeout(soTimeout);
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : Version(org.apache.geode.internal.Version) InputStream(java.io.InputStream) IncompatibleVersionException(org.apache.geode.cache.IncompatibleVersionException) EOFException(java.io.EOFException) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) Socket(java.net.Socket) UnsupportedVersionException(org.apache.geode.cache.UnsupportedVersionException)

Example 33 with SocketAddress

use of java.net.SocketAddress in project beam by apache.

the class SocketAddressFactoryTest method testHostPortSocket.

@Test
public void testHostPortSocket() {
    SocketAddress socketAddress = SocketAddressFactory.createFrom("localhost:123");
    assertThat(socketAddress, instanceOf(InetSocketAddress.class));
    assertEquals("localhost", ((InetSocketAddress) socketAddress).getHostString());
    assertEquals(123, ((InetSocketAddress) socketAddress).getPort());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 34 with SocketAddress

use of java.net.SocketAddress in project beam by apache.

the class SocketAddressFactoryTest method testDomainSocket.

@Test
public void testDomainSocket() throws Exception {
    File tmpFile = tmpFolder.newFile();
    SocketAddress socketAddress = SocketAddressFactory.createFrom("unix://" + tmpFile.getAbsolutePath());
    assertThat(socketAddress, instanceOf(DomainSocketAddress.class));
    assertEquals(tmpFile.getAbsolutePath(), ((DomainSocketAddress) socketAddress).path());
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) SocketAddress(java.net.SocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File) Test(org.junit.Test)

Example 35 with SocketAddress

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

the class DatagramChannelImpl method receive.

@Override
public SocketAddress receive(ByteBuffer target) throws IOException {
    target.checkWritable();
    checkOpen();
    if (!isBound) {
        return null;
    }
    SocketAddress retAddr = null;
    try {
        begin();
        // receive real data packet, (not peek)
        synchronized (readLock) {
            boolean loop = isBlocking();
            if (!target.isDirect()) {
                retAddr = receiveImpl(target, loop);
            } else {
                retAddr = receiveDirectImpl(target, loop);
            }
        }
    } catch (InterruptedIOException e) {
        // this line used in Linux
        return null;
    } finally {
        end(retAddr != null);
    }
    return retAddr;
}
Also used : InterruptedIOException(java.io.InterruptedIOException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

SocketAddress (java.net.SocketAddress)717 InetSocketAddress (java.net.InetSocketAddress)542 Test (org.junit.Test)169 IOException (java.io.IOException)154 Socket (java.net.Socket)105 InetAddress (java.net.InetAddress)56 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)42 Proxy (java.net.Proxy)39 ArrayList (java.util.ArrayList)37 SocketChannel (java.nio.channels.SocketChannel)36 SocketException (java.net.SocketException)34 ServerSocket (java.net.ServerSocket)33 HashMap (java.util.HashMap)33 Channel (org.jboss.netty.channel.Channel)33 UnknownHostException (java.net.UnknownHostException)32 ByteBuffer (java.nio.ByteBuffer)32 Map (java.util.Map)31 Set (java.util.Set)31 Channel (io.netty.channel.Channel)30 HashSet (java.util.HashSet)30