April 05
Prof. Ismael H. F. Santos -  ismael@tecgraf.puc-rio.br                                                          2
Implementing a Server
n1. Open the Server Socket:
n ServerSocket server; 
n   DataOutputStream os;
n   DataInputStream is;
n   server = new ServerSocket( PORT );
n2. Wait for the Client Request:
n Socket client = server.accept();
n3. Create I/O streams for communicating to the client
n is = new DataInputStream( client.getInputStream() );
n   os = new DataOutputStream( client.getOutputStream() );
n4. Perform communication with client
n   Receive from client: String line = is.readLine();
n Send to client: os.writeBytes("Hello\n");
n5. Close sockets:    client.close();
nFor multithreaded server:
n  while(true) {
n i. wait for client requests (step 2 above)
n      ii. create a thread with “client” socket as parameter (the thread creates streams (as in step (3) and does communication as stated  in (4). Remove thread once service is provided.
n}