ServerSocket server = new ServerSocket (service_port);
for (;;)
{
// Accept an incoming connection
Socket connection = server.accept();
// Process in another thread
new SimpleServer(connection).run();
}
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");
}
}