As Torsten said, it's pretty simple. Here is a snippet (for illustration
only... you could punch many holes in this :-) It does not parse the
HTTP headers or anything like that, but that's pretty simple.
public class SampleServer
{
public static void main(String[] args)
{
if (args.length != 1)
{
System.err.println(USAGE);
}
int port = -1;
try
{
port = Integer.parseInt(args[0]);
}
catch (NumberFormatException e)
{
System.err.println(USAGE);
System.exit(1);
}
try
{
ServerSocket ss = new ServerSocket(port);
mDispatchThread = new DispatchThread(ss);
mDispatchThread.start();
}
catch (IOException e)
{
DHLLog.getInstance().fatal(SampleServer.class, "error
setting up socket", e);
}
}
static class DispatchThread
extends Thread
{
DispatchThread(ServerSocket ss)
{
mSS = ss;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run()
{
Socket s = null;
char[] buffer = new char[1024];
do {
try {
s = mSS.accept();
}
catch (IOException e) {
System.err.println("Error while in accept: " +
e.getMessage());
System.exit(1);
}
// REQUEST: s.getInputStream()
// RESPONSE: s.getOuputStream()
while (true);
}
private boolean mKeepRunning = true;
private ServerSocket mSS;
}
private static final String USAGE = "usage: SampleServer <portNumber>";
}
John Smith wrote:
I am doing some research regarding writing a small webserver in java...
So my question is:
How long would it take to write a small webserver in java, by say some
one who has little experience in java but has a strong programming
background ?
Would it be possible to run this from a Windoze CE ?
Any ideas and links greatly appreciated !