Java Reference
In-Depth Information
while
while
(
true
true
) {
final
final
Socket clntSock
=
sock
.
accept
();
Thread t
=
new
new
Thread
(){
public
public
void
void
run
() {
new
new
Handler
(
Httpd
.
this
).
process
(
clntSock
);
}
};
t
.
start
();
}
}
/** Construct a server object for a given port number */
Httpd
()
throws
throws
Exception
{
wsp
=
new
new
FileProperties
(
"httpd.properties"
);
rootDir
=
wsp
.
getProperty
(
"rootDir"
,
"."
);
mimeTypes
=
new
new
FileProperties
(
wsp
.
getProperty
(
"mimeProperties"
,
"mime.properties"
));
}
public
public
void
void
startServer
(
int
int
portNum
)
throws
throws
Exception
{
String portNumString
=
null
null
;
iif
(
portNum
==
HTTP
) {
portNumString
=
wsp
.
getProperty
(
"portNum"
);
iif
(
portNumString
!=
null
null
) {
portNum
=
Integer
.
parseInt
(
portNumString
);
}
}
sock
=
new
new
ServerSocket
(
portNum
);
System
.
out
.
println
(
"Listening on port "
+
portNum
);
}
public
public
String
getMimeType
(
String type
) {
return
return
mimeTypes
.
getProperty
(
type
);
}
public
public
String
getMimeType
(
String type
,
String dflt
) {
return
return
mimeTypes
.
getProperty
(
type
,
dflt
);
}
public
public
String
getServerProperty
(
String name
) {
return
return
wsp
.
getProperty
(
name
);
}
public
public
String
getRootDir
() {
return
return
rootDir
;