int thePort;
ServerSocket ss;
Socket theConnection;
FileInputStream theFile;
// cache the file
try {
theFile = new FileInputStream(args[0]);
DataInputStream dis = new DataInputStream(theFile);
if (args[0].endsWith(".html") || args[0].endsWith(".htm")) {
ContentType = "text/html";
}
else {
ContentType = "text/plain";
}
try {
String thisLine;
while ((thisLine = dis.readLine()) != null) {
theData += thisLine + "\n";
}
}
catch (Exception e) {
System.err.println("Error: " + e);
}
}
catch (Exception e) {
System.err.println(e);
System.err.println("Usage: java onefile filename port");
System.exit(1);
}
// set the port to listen on
try {
thePort = Integer.parseInt(args[1]);
if (thePort < 0 || thePort > 65535) thePort = 80;
}
catch (Exception e) {
thePort = 80;
}
try {
ss = new ServerSocket(thePort);
System.out.println("Accepting connections on port "
+ ss.getLocalPort());
System.out.println("Data to be sent:");
System.out.println(theData);
while (true) {
onefile fs = new onefile(ss.accept());
fs.start();
}
}
catch (IOException e) {
}