Examples of NioTcpClient


Examples of org.apache.mina.transport.nio.NioTcpClient

public class NioTcpClientTimeoutTest {

    @Test
    @Ignore
    public void timeout() throws IOException, InterruptedException {
        NioTcpClient client = new NioTcpClient();
        client.setConnectTimeoutMillis(1000);

        ServerSocket server = new ServerSocket();
        try {
            server.bind(null);
            IoFuture<IoSession> cf = client.connect(new InetSocketAddress("localhost", server.getLocalPort()));
            Thread.sleep(5000);
            IoSession session = cf.get();
            System.err.println(session);
            Assert.fail();
        } catch (ExecutionException ex) {
View Full Code Here

Examples of org.apache.mina.transport.nio.NioTcpClient

     * Create an old IO server and use a bunch of MINA client on it. Test if the events occurs correctly in the
     * different IoFilters.
     */
    @Test
    public void generate_all_kind_of_client_event() throws IOException, InterruptedException, ExecutionException {
        NioTcpClient client = new NioTcpClient();
        client.setFilters(new MyCodec(), new Handler());

        ServerSocket serverSocket = new ServerSocket();
        serverSocket.bind(null);
        int port = serverSocket.getLocalPort();

        // warm up
        Thread.sleep(100);
        final long t0 = System.currentTimeMillis();

        // now connect the clients

        List<IoFuture<IoSession>> cf = new ArrayList<IoFuture<IoSession>>();
        for (int i = 0; i < CLIENT_COUNT; i++) {
            cf.add(client.connect(new InetSocketAddress("localhost", port)));
        }

        Socket[] clientSockets = new Socket[CLIENT_COUNT];
        for (int i = 0; i < CLIENT_COUNT; i++) {
            clientSockets[i] = serverSocket.accept();
View Full Code Here

Examples of org.apache.mina.transport.nio.NioTcpClient

        NioTcpServer server = new NioTcpServer();
        server.setIoHandler(new Handler());
        server.bind(0);

        NioTcpClient client = new NioTcpClient();
        client.setIoHandler(new AbstractIoHandler() {
        });
        for (int i = 0; i < CLIENT_COUNT; ++i) {
            client.connect(new InetSocketAddress(server.getServerSocketChannel().socket().getLocalPort())).get();
        }
        client.disconnect();
        assertTrue(closedLatch.await(WAIT_TIME, TimeUnit.MILLISECONDS));
    }
View Full Code Here

Examples of org.apache.mina.transport.nio.NioTcpClient

    /**
     * {@inheritDoc}
     */
    public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
        client = new NioTcpClient();
        client.getSessionConfig().setSendBufferSize(64 * 1024);
        client.getSessionConfig().setTcpNoDelay(true);
        client.setIoHandler(new IoHandler() {
            private void sendMessage(IoSession session, byte[] data) {
                ByteBuffer iobuf = ByteBuffer.wrap(data);
View Full Code Here

Examples of org.apache.mina.transport.nio.NioTcpClient

    static final private Logger LOG = LoggerFactory.getLogger(NioEchoServer.class);

    public static void main(String[] args) {
        LOG.info("starting echo client");

        final NioTcpClient client = new NioTcpClient();
        client.setFilters();
        client.setIoHandler(new AbstractIoHandler() {
            @Override
            public void sessionOpened(final IoSession session) {
                LOG.info("session opened {}", session);
            }

            @Override
            public void messageReceived(IoSession session, Object message) {
                LOG.info("message received {}", message);
                if (message instanceof ByteBuffer) {
                    LOG.info("echoing");
                    session.write(message);
                }
            }

            @Override
            public void messageSent(IoSession session, Object message) {
                LOG.info("message sent {}", message);
            }

            @Override
            public void sessionClosed(IoSession session) {
                LOG.info("session closed {}", session);
            }
        });

        try {
            IoFuture<IoSession> future = client.connect(new InetSocketAddress("localhost", 9999));

            try {
                IoSession session = future.get();
                LOG.info("session connected : {}", session);
            } catch (ExecutionException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.