Package test

Source Code of test.NetworkingTest

package test;

import com.grt192.networking.GRTClientSocket;
import com.grt192.networking.SocketEvent;
import com.grt192.networking.SocketListener;

public class NetworkingTest {

  static String host = "127.0.0.1";
  static int port = 80;

  public static void main(String[] args) {
    System.out.println("Starting Network Test");
    GRTClientSocket connection = new GRTClientSocket(host, port);
    connection.addSocketListener(new SocketListener() {

      public void dataRecieved(SocketEvent e) {
        System.out.println("< " + e.getData());
      }

      public void onConnect(SocketEvent e) {
        System.out.println("Connected!");
      }

      public void onDisconnect(SocketEvent e) {
        System.out.println("Disconnected!");
      }
    });
    connection.connect();
    connection.start();
    try {
      connection.sendData("GET /index.html HTTP/1.0\n");
      Thread.sleep(4000);
      connection.disconnect();
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
    }

  }
}
TOP

Related Classes of test.NetworkingTest

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.