Java how to handle HTTP GET request after establishing TCP connection
Java
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();
Also in Java:
- Title
- Don't use a line-beased input after a token-based input.
- Category
- Java
- Title
- run static method java
- Category
- Java
- Title
- how lock horizontal orientation android
- Category
- Java
- Title
- random java
- Category
- Java
- Title
- serialversionuid java
- Category
- Java
- Title
- using class in java
- Category
- Java
- Title
- java packages example
- Category
- Java
- Title
- java 8 function supplier consumer
- Category
- Java
- Title
- java calendar add minutes
- Category
- Java
- Title
- how to write sensor data into file android studio
- Category
- Java
- Title
- java command line arguments
- Category
- Java
- Title
- priority queue java reverse order
- Category
- Java
- Title
- int to binary java
- Category
- Java
- Title
- java prev_permutation
- Category
- Java
- Title
- how to add to a file in java
- Category
- Java
- Title
- java public static void main
- Category
- Java
- Title
- how to bubblesort a string array in java
- Category
- Java
- Title
- java method
- Category
- Java
- Title
- how to have a only number type in java
- Category
- Java
- Title
- selection sort in java
- Category
- Java
- Title
- java 8 seconds to days
- Category
- Java
- Title
- sdkmanager JAVA_HOME invalid directory
- Category
- Java
- Title
- java for each
- Category
- Java
- Title
- append to arraylist by index java
- Category
- Java
- Title
- compile java
- Category
- Java
- Title
- set java
- Category
- Java
- Title
- primitive data types in java
- Category
- Java
- Title
- java count substring occurrences in string
- Category
- Java
- Title
- read from elasticsearch in spark
- Category
- Java
- Title
- palindrome function java
- Category
- Java
- Title
- how take inputs in java with message
- Category
- Java
- Title
- find the triplet sum in java linked list
- Category
- Java
- Title
- how to add a keylistener to a jframe
- Category
- Java
- Title
- java map geeksforgeeks
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- processing pi
- Category
- Java
- Title
- deleting elements of an array in java
- Category
- Java
- Title
- diagonal difference hackerrank solution in java 8 using list
- Category
- Java
- Title
- java how to read a text file
- Category
- Java
- Title
- create java windows application
- Category
- Java
- Title
- org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder
- Category
- Java
- Title
- import java.util.hashset
- Category
- Java
- Title
- java replaceall single character
- Category
- Java
- Title
- int4 spring jpa failling create command
- Category
- Java
- Title
- java list contains object with property
- Category
- Java
- Title
- how to instanciate map.entry java
- Category
- Java
- Title
- init admob
- Category
- Java
- Title
- NumSelfDivisors java
- Category
- Java
- Title
- java get input
- Category
- Java
- Title
- try block in java
- Category
- Java
- Title
- java permutation
- Category
- Java
- Title
- how to add jar in maven java application in netbeans
- Category
- Java
- Title
- java convert char to int
- Category
- Java
- Title
- expression régulière téléphone java
- Category
- Java
- Title
- write an object java in a file
- Category
- Java
- Title
- how to add java_home in mac
- Category
- Java
- Title
- random boolean java
- Category
- Java
- Title
- java string length validation regex
- Category
- Java
- Title
- compile java to jar in mac
- Category
- Java
- Title
- how to add all list elements at once in java
- Category
- Java
- Title
- split by new line java
- Category
- Java
- Title
- java setter
- Category
- Java
- Title
- eliminar fila jtable java
- Category
- Java
- Title
- how to substring in java
- Category
- Java
- Title
- round no in java
- Category
- Java
- Title
- java read file bufferedreader
- Category
- Java
- Title
- java 8 find in list by property
- Category
- Java
- Title
- get long from date java
- Category
- Java
- Title
- do while loop java
- Category
- Java
- Title
- check if a string is a substring of another string java
- Category
- Java
- Title
- how to append to a string in java
- Category
- Java
- Title
- java logical operator
- Category
- Java
- Title
- iterate through hashmap in java
- Category
- Java
- Title
- java 8 findany on null list
- Category
- Java
- Title
- how to make an arraylist java
- Category
- Java
- Title
- java 8 iterating and manipulating list
- Category
- Java
- Title
- kotlin android intent pass data
- Category
- Java
- Title
- arrays.fill java
- Category
- Java
- Title
- center textview programmatically android
- Category
- Java
- Title
- how to push an element in hashset java
- Category
- Java
- Title
- split method in java
- Category
- Java
- Title
- big integer java
- Category
- Java
- Title
- java string split underscore
- Category
- Java
- Title
- import java.util.*;
- Category
- Java
- Title
- how to check if a string contains only alphabets and space in java
- Category
- Java
- Title
- online money transfer andhra bank
- Category
- Java
- Title
- rgb to hex java
- Category
- Java
- Title
- java best way to concatenate strings
- Category
- Java
- Title
- how to calculate min, max and average and write the output into into a text file in java
- Category
- Java
- Title
- java how to serialize a file into a local server
- Category
- Java
- Title
- kotlin jsonobject get nested
- Category
- Java
- Title
- splitting using regex java
- Category
- Java
- Title
- is self divisor java
- Category
- Java
- Title
- arraylist with values
- Category
- Java
- Title
- LocalRegistry java rebind() java8
- Category
- Java
- Title
- how to print in java
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- Scanner library showing element not found exception
- Category
- Java
- Title
- para que sirve getcontentpane en java
- Category
- Java
- Title
- how to print to the console in java
- Category
- Java