Java Reference
In-Depth Information
* or error.
*
* @param socket The client socket.
* @throws IOException Thrown if any sort of error occurs.
*/
private void handleClientSession(Socket socket)
throws IOException
{
// setup to read from the socket in lines
InputStream is = socket.getInputStream();
InputStreamReader inputStreamReader =
new InputStreamReader(is);
BufferedReader in = new BufferedReader(inputStreamReader);
// setup to write to socket in lines
OutputStream os = socket.getOutputStream();
// read in the first line
System.out.println("**New Request**");
String first = in.readLine();
System.out.println(first);
// read in headers and post data
String line;
do
{
line = in.readLine();
System.out.println(line);
} while (line!=null && line.trim().length() > 0);
// write the HTTP response
StringTokenizer tok = new StringTokenizer(first);
String verb = (String) tok.nextElement();
String path = (String) tok.nextElement();
if (verb.equalsIgnoreCase("GET"))
sendFile(os, path);
else
error(os, 500, "Unsupported command");
// close everything up
os.close();
in.close();
socket.close();
}
Search WWH ::




Custom Search