View Single Post
  #2 (permalink)  
Old 04-01-2007, 11:36 AM
goldhouse goldhouse is offline
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
Code:
ServerSocket server = new ServerSocket (service_port); for (;;) { // Accept an incoming connection Socket connection = server.accept(); // Process in another thread new SimpleServer(connection).run(); }

Code:
public void run() { try { DataInputStream din = new DataInputStream ( m_connection.getInputStream() ); PrintStream pout = new PrintStream ( m_connection.getOutputStream() ); // Read line from client String data = din.readLine(); // Check to see if we should simulate a stalled server if (shallWeStall) { // Yes .. so reset flag and stall shallWeStall = false; try { Thread.sleep (20000); } catch (InterruptedException ie ) {} } else { // No.... but we will next time shallWeStall = true; } // Echo data back to clinet pout.println (data); // Close connection m_connection.close(); } catch (IOException ioe) { System.err.println ("I/O error"); } }
Reply With Quote