Java Reference
In-Depth Information
package mmi.sockets;
import java.net.*;
import java.io.*;
import java.util.*;
import mmi.*;
public class DSocketListener extends DActivity
implements DObserver{
private ServerSocket serverSocket;
private static final int PORT # 2002;
public DSocketListener(DProcess process)
throws java.rmi.RemoteException {
super (process);
try {
serverSocket # new ServerSocket(PORT);
} catch (IOException ioe){ ioe.printStackTrace(); }
}
public void step() {
try {
// SocketListener waiting for a connection request
System.out.println("DSocketListener waiting" !
"for a connection request");
Socket socket # serverSocket.accept();
// creates and starts the socket activity that
// interacts wiht the client
process.startActivity( new DSocketActivity
(process, socket));
} catch (IOException e){ e.printStackTrace(); }
}
}
public class DSocketActivity extends DActivity
implements DObserver {
private Socket socket # null ;
// created by DSocketListener
private BufferedReader input # null ;
// the socket's input buffer
private PrintWriter output # null ;
// the socket's output buffer
private DActivity service # null ;
// the requested service
private DParser parser # null ;
// the parser for the requested service
private ArrayList eventList # new ArrayList();
// list of incoming events
private boolean pushMode # false ;
DSocketActivity(DProcess process, Socket socket)
throws java.rmi.RemoteException{
Search WWH ::




Custom Search