At 7:19 PM -0700 04/23/2001, [EMAIL PROTECTED] wrote:
>On Mon, 23 Apr 2001, Arun Katkere wrote:
>In general you need to do something to unblock the accept thread, and 3.2
>doesn't have this in.
Yes, I remember now. You're absolutely right. You need
serverSocket.setSoTimeout() to break the accept periodically. Here's
how I did it in my app.
Notice the comment: apparently I got this from an early version of Tomcat.
public void run()
{
if (serverSocket != null) // original is server
{
isListening = true;
while(isListening)
{
try
{
Socket clientSocket = serverSocket.accept();
SocketServer clone = (SocketServer)clone();
clone.serverSocket = null;
clone.clientSocket = clientSocket;
clone.thread = new Thread(clone, name+"Clone");
clone.thread.start();
}
catch (InterruptedIOException e)
{
/**
* Ignore periodic SO_TIMEOUT interrupts
* Without this the accept call never returns when the serversocket
* is closed, and all subsequent runs fail with "port 8082 busy".
* I found this in the Tomcat http server code.
*/
}
catch (Throwable e)
{ e.printStackTrace(); isListening = false; }
}
}
else run(clientSocket);
}
void startServer(int port) throws UserFault
{
if (thread == null)
{
try
{
serverSocket = new ServerSocket(port);
serverSocket.setSoTimeout(WAKEUP_INTERVAL);
}
catch (IOException e)
{
throw UserFault.errEnablerPortBusy(port);
}
thread = new Thread(this, name+"Master");
isListening = true;
thread.start();
}
}
--
---
Brad Cox, Ph.D.; [EMAIL PROTECTED]
Phone: 703 361 4751 Cell: 703 919-9623
http://virtualschool.edu