Package com.firefly.net.support

Examples of com.firefly.net.support.SimpleTcpClient


  }

  public static void main(String[] args) {
    ExecutorService executorService = Executors.newFixedThreadPool(THREAD);
    final SimpleTcpClient client = new SimpleTcpClient("localhost", 9900,
        new StringLineDecoder(), new StringLineEncoder());
    final CyclicBarrier barrier = new CyclicBarrier(THREAD, new StatTask());

    for (int i = 0; i < THREAD; i++)
      executorService.submit(new ClientSynchronizeTask(client, barrier));
View Full Code Here


import com.firefly.net.support.StringLineEncoder;
import com.firefly.net.support.TcpConnection;

public class SimpleTcpClientExample {
  public static void main(String[] args) {
    final SimpleTcpClient client = new SimpleTcpClient("localhost", 9900,
        new StringLineDecoder(), new StringLineEncoder());
    TcpConnection c = client.connect();
    c.send("hello client 1", new MessageReceiveCallBack() {

      @Override
      public void messageRecieved(Session session, Object obj) {
        System.out.println("con1|" + obj.toString());

      }
    });

    c.send("test client 2", new MessageReceiveCallBack() {

      @Override
      public void messageRecieved(Session session, Object obj) {
        System.out.println("con1|" + obj.toString());

      }
    });

    c.send("test client 3", new MessageReceiveCallBack() {

      @Override
      public void messageRecieved(Session session, Object obj) {
        System.out.println("con1|" + obj.toString());
      }
    });

    c.send("quit", new MessageReceiveCallBack() {

      @Override
      public void messageRecieved(Session session, Object obj) {
        System.out.println("con1|" + obj.toString());
      }
    });

    TcpConnection c2 = client.connect();
    System.out.println("con2|" + c2.send("getfile"));
    c2.close(false);

   
  }
View Full Code Here

    server.setConfig(config);
    server.start("localhost", 9900);

    final int LOOP = 50;
    ExecutorService executorService = Executors.newFixedThreadPool(LOOP);
    final SimpleTcpClient client = new SimpleTcpClient("localhost", 9900,
        new StringLineDecoder(), new StringLineEncoder());

    for (int i = 0; i < LOOP; i++) {
      executorService.submit(new Runnable() {
        @Override
        public void run() {
          final TcpConnection c = client.connect();
          Assert.assertThat(c.isOpen(), is(true));
          log.debug("main thread {}", Thread.currentThread()
              .toString());
          Assert.assertThat((String) c.send("hello client"), is("hello client"));
          Assert.assertThat((String) c.send("hello multithread test"), is("hello multithread test"));
          Assert.assertThat((String) c.send("getfile"), is("zero copy file transfers"));
          Assert.assertThat((String) c.send("quit"), is("bye!"));
          log.debug("complete session {}", c.getId());
        }
      });

    }

    final TcpConnection c = client.connect();
    Assert.assertThat((String) c.send("hello client 2"), is("hello client 2"));
    Assert.assertThat((String) c.send("quit"), is("bye!"));
  }
View Full Code Here

    }
    DATA = new String(data);
   

    ExecutorService executorService = Executors.newFixedThreadPool(THREAD);
    final SimpleTcpClient client = new SimpleTcpClient(host, port,
        new StringLineDecoder(), new StringLineEncoder());
    for (int i = 0; i < THREAD; i++) {
      tcpConnections[i] = client.connect();
    }
    final CyclicBarrier barrier = new CyclicBarrier(THREAD, new StatTask());

    if (asyn == 0) {
      log.info("synchronize test");
View Full Code Here

TOP

Related Classes of com.firefly.net.support.SimpleTcpClient

Copyright © 2018 www.massapicom. 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.