package net.ddns.mucaho.jnetrobust.example.simple;


import net.ddns.mucaho.jnetrobust.example.DefaultHost;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Queue;

public class ChatMain {
    private static InetSocketAddress ADDRESS_A;
    private static InetSocketAddress ADDRESS_B;

    static {
        try {
            ADDRESS_A = new InetSocketAddress(InetAddress.getLocalHost(), 12345);
            ADDRESS_B = new InetSocketAddress(InetAddress.getLocalHost(), 12346);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

    public static void main (String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        // setup host A
        DefaultHost<String> hostA = new DefaultHost<String>("A", ADDRESS_A, ADDRESS_B,
                String.class, new DefaultHost.DataListener<String>() {
            @Override
            public void handleOrderedData(String orderedData) {}
            @Override
            public void handleNewestData(String newestData) {}
        });

        // setup host B
        DefaultHost<String> hostB = new DefaultHost<String>("B", ADDRESS_B, ADDRESS_A,
                String.class, new DefaultHost.DataListener<String>() {
            @Override
            public void handleOrderedData(String orderedData) {}
            @Override
            public void handleNewestData(String newestData) {}
        });

        Queue<String> receivedMessages;

        // send from A
        hostA.send("Hi!");
        hostA.send("How you doing?");

        Thread.sleep(100);

        // receive at B
        receivedMessages = hostB.receive();
        for (String receivedMessage: receivedMessages)
            System.out.println("[B]: "+receivedMessage);

        // send from B
        hostB.send("Howdy! Fine, thanks.");

        Thread.sleep(100);

        // receive at A
        receivedMessages = hostA.receive();
        for (String receivedMessage: receivedMessages)
            System.out.println("[A]: "+receivedMessage);
    }
}

@@ -106,36 +106,8 @@
 t;%0A%0A
-import java.io.IOException;%0A
 impo
@@ -170,46 +170,8 @@
 ss;%0A
-import java.net.UnknownHostException;%0A
 impo
@@ -216,38 +216,37 @@
 Main %7B%0A    p
-rivate
+ublic
  static 
 InetSocketAd
@@ -237,124 +237,104 @@
 tic 
-InetSocketAddress ADDRESS_A;%0A    private static InetSocketAddress ADDRESS_B;%0A%0A    static %7B%0A        try %7B%0A           
+void main (String%5B%5D args) throws Exception %7B%0A        // host addresses%0A        InetSocketAddress
  ADD
@@ -408,19 +408,33 @@
         
-   
+InetSocketAddress
  ADDRESS
@@ -500,230 +500,34 @@
 6);%0A
-        %7D catch (UnknownHostException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    public static void main (String%5B%5D args) throws IOException, InterruptedException, ClassNotFoundException %7B%0A        // setup h
+%0A        // setup DefaultH
 ost 
@@ -888,17 +888,24 @@
 / setup 
-h
+DefaultH
 ost B%0A  

Simplify simple example.