Commit 5639964d authored by Rohan  Kumar's avatar Rohan Kumar
Browse files

"push"

parent c7c03df6
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
package object_detection;

import java.net.ServerSocket;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.FileWriter; // file writing support
import java.nio.charset.StandardCharsets;

public class ObjectDetectionServer {

    public static void main(String[] args) throws Exception {
        final ServerSocket server = new ServerSocket(80); // port 80
        System.out.println("Listening for connection on port 80...");
        while (true) {
            try (Socket clientSocket = server.accept();
                 FileWriter fw = new FileWriter("blank.txt", true); // open file in append mode
            ) {
                InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
                BufferedReader reader = new BufferedReader(isr);
                String line = reader.readLine();
                while (!line.isEmpty()) {
                    System.out.println(line);
                    fw.write(line + "\n"); // write line to file
                    line = reader.readLine();
                }
                fw.flush(); // ensure all data is written to file

                // at this point, run ObjectDetector
                ObjectDetector.run(fw.toString());

                // HTTP response
                String httpResponse = "HTTP/1.1 200 OK\r\n\r\n" + "<html><body><h1>Hello, World!</h1></body></html>";

                // dispatching HTTP response to the client
                OutputStream outputStream = clientSocket.getOutputStream();
                outputStream.write(httpResponse.getBytes(StandardCharsets.UTF_8));
                outputStream.flush();
            } catch (IOException e) {
                e.printStackTrace(); // handle exceptions appropriately
            }
        }
    }
}
+2 −1
Original line number Diff line number Diff line
package object_detection;

public class ObjectDetector {

    static ObjectSet os;

    public static void main(String[] args){
    public static void run(String pathname){

        /* infinite loop of running system:
        1) Get new info from system