Java Reference
In-Depth Information
Import java.net.*;
import java.io.*;
import java.util.*;
import gis.model.*;
public class GisServer implements Runnable {
// server socket listening to incoming requests on PORT
private ServerSocket serverSocket;
private static final int PORT # 2002;
// the list of active services
private ArrayList serviceList # new ArrayList();
private Thread thread # null ;
public GisServer() {
try {
serverSocket # new ServerSocket(PORT);
} catch (Exception e) {e.printStackTrace();}
DBConnector.openDataBase(); // opens the GIS database
thread # new Thread( this );
thread.start();
}
public void run() {
while ( true )
try {
// the server socket is waiting for incoming requests
Socket socket # serverSocket.accept();
// creates the service that interacts with the applet
serviceList.add(new GisService(socket, this));
} catch (IOException e){ e.printStackTrace();}
}
public void disconnect(GisService service) {
serviceList.remove(service);
}
public static void main(String[] args) {
GisServer gisServer # new GisServer();
}
}
public class GisService implements Runnable {
private static String PATH # "gis//";
private Socket socket # null ;
private GisServer server # null ;
private Thread thread;
public GisService(Socket socket, GisServer server) {
this .socket # socket;
this .server # server;
thread # new Thread( this );
thread.start();
}
Search WWH ::




Custom Search