package roombacomm.net; import java.net.*; import java.io.*; public class TextHttpServer { int port = 6767; // the shutdown command received private boolean shutdown = false; public static void main(String[] args) { TextHttpServer server = new TextHttpServer(); server.await(); } public void await() { ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(port, 1, null); } catch (IOException e) { e.printStackTrace(); System.exit(1); } // Loop waiting for a request while (!shutdown) { Socket socket = null; InputStream input = null; OutputStream output = null; try { socket = serverSocket.accept(); input = socket.getInputStream(); output = socket.getOutputStream(); String uri = parseRequest( input ); System.out.println("uri: "+uri); // Close the socket socket.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } } public String parseRequest(InputStream input) { // Read a set of characters from the socket StringBuffer request = new StringBuffer(2048); int i; byte[] buffer = new byte[2048]; try { i = input.read(buffer); } catch (IOException e) { e.printStackTrace(); i = -1; } for (int j=0; j index1) return requestString.substring(index1 + 1, index2); } return null; } }