package lmxnd;

import com.digi.xbee.api.XBee;

public class Lmxnd {
	/*
	public static void main(String[] args) {
		XBee xbee = new XBee();
		try {
			xbee.open("/deb/ttyUSB", 9600);
		} catch (XBeeException ex) {
			System.err.println(ex.getMessage());
			System.err.println("Fatal error. Exiting with code 1.");
			System.exit(1);
		}
	}
	*/
	public static void main(String[] args) {
		System.out.println("Hello, world");
		/*
		 * XBee xbee = new XBee();
		 * xbee.open();
		 */
		
		XBeeNetwork network = new XBeeNetwork();
		runServer(network, 1337);
	}

	private static void runServer(XBeeNetwork network, int port)
	                                                     throws IOException {
		ServerSocket serverSocket = new ServerSocket(port);
		
		while (true) {
			Socket socket = serverSocket.accept();

	}

	private static class RequestServer implements Runnable {
		public ServerLogic(Socket connection, XBeeNetwork network) {
			conn = connection;
			net = network;
		}

		public void run() {
			InputStream in = conn.getInputStream();
			OutputStream out = conn.getOutputStream();

		private Socket conn;
		private XBeeNetwork net;
	}
}

@@ -44,305 +44,251 @@
 ee;%0A
-%0Apublic class Lmxnd %7B%0A%09/*%0A%09public static void main(String%5B%5D args) %7B%0A%09%09XBee xbee = new XBee();%0A%09%09try %7B%0A%09%09%09xbee.open(%22/deb/ttyUSB%22, 9600);%0A%09%09%7D catch (XBeeException ex) %7B%0A%09%09%09System.err.println(ex.getMessage());%0A%09%09%09System.err.println(%22Fatal error. Exiting with code 1.%22);%0A%09%09%09System.exit(1);%0A%09%09%7D%0A%09%7D%0A%09*/
+import com.sun.net.httpserver.HttpServer;%0Aimport com.sun.net.httpserver.HttpHandler;%0Aimport com.sun.net.httpserver.HttpExchange;%0Aimport java.net.InetSocketAddress;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0A%0Apublic class Lmxnd %7B%0A
 %0A%09pu
@@ -368,69 +368,8 @@
 %22);%0A
-%09%09/*%0A%09%09 * XBee xbee = new XBee();%0A%09%09 * xbee.open();%0A%09%09 */%0A%09%09%0A
 %09%09XB
@@ -411,292 +411,306 @@
 ();%0A
+%0A
 %09%09
-runServer(network, 1337);%0A%09%7D%0A%0A%09private static void runServer(XBeeNetwork network, int port)%0A%09                                                     throws IOException %7B%0A%09%09S
+try %7B%0A%09%09%09HttpServer server%0A%09%09%09    = HttpServer.create(new InetSocketAddress(1337), 0);%0A%09%09%09s
 erver
-Socket serverSocket = new ServerSocket(port);%0A%09%09%0A%09%09while (true) %7B%0A%09%09%09Socket socket = serverSocket.accep
+.createContext(%22/%22, new ServerHandler(network));%0A%09%09%09server.setExecutor(null);%0A%09%09%09server.start();%0A%09%09%7D catch (IOException ex) %7B%0A%09%09%09System.err.println(%22Could not create server.%22);%0A%09%09%09System.exi
 t(
+1
 );
+%0A%09%09%7D
 %0A%0A%09%7D
@@ -737,19 +737,19 @@
 ass 
-RequestServ
+ServerHandl
 er i
@@ -762,19 +762,23 @@
 nts 
-Runnab
+HttpHand
 le
+r
  %7B%0A
+%0A
 %09%09pu
@@ -792,33 +792,16 @@
 rver
-Logic(Socket connection, 
+Handler(
 XBee
@@ -826,115 +826,192 @@
 %0A%09%09%09
-conn = connection;%0A%09%09%09net = network;%0A%09%09%7D%0A%0A%09%09public void run() %7B%0A%09%09%09InputStream in = conn.getInputStream(
+net = network;%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void handle(HttpExchange exchange) %7B%0A%09%09%09try %7B%0A%09%09%09%09String jsonObject = net.view();%0A%09%09%09%09exchange.sendResponseHeaders(200, jsonObject.length()
 );%0A
+%09
 %09%09%09O
@@ -1029,58 +1029,305 @@
  out
- = conn.getOutputStream
+putStream = exchange.getResponseBody();%0A%09%09%09%09outputStream.write(jsonObject.getBytes
 ()
+)
 ;%0A
-%0A%09%09private Socket conn;
+%09%09%09%7D catch (Exception ex) %7B%0A%09%09%09%09System.err.println(%0A%09%09%09%09    %22Exception encountered while handling HTTP request:%22);%0A%09%09%09%09System.err.println(ex.getMessage());%0A%09%09%09%09System.err.println(%22%5CnContinuing...%22);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09
 %0A%09%09p

Add working HTTP server