import java.net.*; /** * @author nthrasher * * A sample program which demonstrates the capability of the hardware discovery nodes. */ public class TestNodeImpl { TestNodeImpl() { //create addresses InetSocketAddress address1 = null; InetSocketAddress address2 = null; try { address1 = new InetSocketAddress(InetAddress.getLocalHost(), 11778); address2 = new InetSocketAddress(InetAddress.getLocalHost(), 11779); } catch (UnknownHostException e) { e.printStackTrace(); } //create node1; NodeImpl node1 = new NodeImpl("Node1", address1); node1.ping(); //create node2 NodeImpl node2 = new NodeImpl("Node2", address2); node2.ping(); try { Thread.sleep(200); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //create packet and set destination to be node2 Packet msg = new Packet(); msg.setDest(node1.getConnectionInfo("Node2")); msg.setPayload(new String("[FROM NODE 1] Testing 1, 2, 3...").getBytes()); // send message from node1 to node2 node1.sendPacket(msg); //create packet and set destination to be node1 msg.setDest(node2.getConnectionInfo("Node1")); msg.setPayload(new String("[FROM NODE 2] Testing 1, 2, 3...").getBytes()); //send message from node2 to node1 node2.sendPacket(msg); //make sure to close down all connections (threads) node1.close(); node2.close(); } public static void main(String[] args) { new TestNodeImpl(); } }