Java Reference
In-Depth Information
/**
* DVDSocketServer is the class that handles socket client requests and
* passes the request to the database. The class recieves parameters in
* <code>DVDCommand</code> objects and returns results in
* <code>DVDResult</code> objects.
* @version 2.0
*/
public class DvdSocketServer extends Thread {
private String dbLocation = null;
private int port = 3000;
/**
* Starts the socket server
*
* @param argv Command line arguments.
* @throws IOException Thrown if the socket server fails to start.
*/
public static void main(String argv[]) {
register(".", 3000);
}
public static void register(String dbLocation, int port) {
new DvdSocketServer(dbLocation, port).start();
}
public DvdSocketServer(String dbLocation, int port) {
this.dbLocation = dbLocation;
this.port = port;
}
public void run() {
try {
listenForConnections();
} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(-1);
}
}
public void listenForConnections() throws IOException {
ServerSocket aServerSocket = new ServerSocket(port);
//block for 60,000 msecs or 1 minute
aServerSocket.setSoTimeout(60000);
(Logger.getLogger("sampleproject.sockets")).log(Level.INFO,
"a server socket created on port " +
aServerSocket.getLocalPort());
Search WWH ::




Custom Search