Answers for "check for connection request java"

1

check network connection php

$response = null;
system("ping -c 1 google.com", $response);
if($response == 0)
{
    // this means you are connected
}
Posted by: Guest on April-08-2020
0

Java how to handle HTTP GET request after establishing TCP connection

ServerSocket serverSock = new ServerSocket(6789);
Socket sock = serverSock.accept();

InputStream sis = sock.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(sis));
String request = br.readLine(); // Now you get GET index.html HTTP/1.1`
String[] requestParam = request.split(" ");
String path = requestParam[1];

PrintWriter out = new PrintWriter(sock.getOutputStream(), true);
File file = new File(path);
if (!file.exists()) {
     out.write("HTTP 404"); // the file does not exists
}
FileReader fr = new FileReader(file);
BufferedReader bfr = new BufferedReader(fr);
String line;
while ((line = bfr.readLine()) != null) {
    out.write(line);
}

bfr.close();
br.close();
out.close();
Posted by: Guest on May-19-2020

Code answers related to "check for connection request java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language