Java Reference
In-Depth Information
public WebServer(int port, String httproot) throws IOException
{
serverSocket = new ServerSocket(port);
this.httproot = httproot;
}
/**
* The run method endlessly waits for connections.
* As each connection is opened(from web browsers)
* the connection is passed off to handleClientSession.
*/
public void run()
{
for (;;)
{
try
{
Socket clientSocket = serverSocket.accept();
handleClientSession(clientSocket);
} catch (IOException e)
{
e.printStackTrace();
}
}
}
/**
* Add a slash to the end of a path, if there is not a slash
* there already. This method adds the correct type of slash,
* depending on the operating system.
*
* @param path The path to add a slash to.
* @return The path with a slash added.
*/
private String addSlash(String path)
{
path = path.trim();
if (path.endsWith("" + File.separatorChar))
return path;
else
return path + File.separatorChar;
}
/**
* Handle a client session. This method displays the incoming
* HTTP request and passes the response off to either sendFile
Search WWH ::




Custom Search