Package com.peterhi.working

Examples of com.peterhi.working.EndpointImpl


import com.peterhi.working.Listener;

public class Server {

  public static void main(String[] args) throws Exception {
    EndpointImpl endpoint = new EndpointImpl(new DatagramSocket(22222));
    endpoint.addListener(new Listener() {
      @Override
      public void update(Event event) {
        try {
          InputStream stream = event.getInputStream();
         
          if (stream.available() == 0) {
            System.out.println();
          }
         
          System.out.println("Received " + stream.available() + " bytes of " +
            (event.isReliable() ? "reliable" : "unreliable") + " data.");
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    });
   
    endpoint.run();
  }
View Full Code Here


import com.peterhi.working.EndpointImpl;

public class Client {

  public static void main(String[] args) throws Exception {
    EndpointImpl endpoint = new EndpointImpl(new DatagramSocket());
    SocketAddress address = new InetSocketAddress(InetAddress.getByName("www.peterhi.com"), 22222);
//    SocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 22222);
    endpoint.run();
    System.out.println("unreliable sent: " + endpoint.send(address, new byte[512], 0, 512, false));
    long justnow = System.currentTimeMillis();
    System.out.println("reliable sent: " + endpoint.send(address, new byte[507 * 65536], 0, 507 * 65536, true));
    long now = System.currentTimeMillis();
    System.out.println("time = " + (now - justnow));
    System.exit(0);
  }
View Full Code Here

TOP

Related Classes of com.peterhi.working.EndpointImpl

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.