当前位置: 技术问答>java相关
如果使用套接字编程,增样控制连接超时?
来源: 互联网 发布时间:2015-07-17
本文导语: 上面 | Socket.setSoTimeout(int timeout) | try { ServerSocket mServerSocket = new ServerSocket(localRPort,5); } catch(IOException Serverioe) { System.err.println("Cannot create ServerSocket error: " + Serverioe); ...
上面
|
Socket.setSoTimeout(int timeout)
|
try
{
ServerSocket mServerSocket = new ServerSocket(localRPort,5);
}
catch(IOException Serverioe)
{
System.err.println("Cannot create ServerSocket error: " + Serverioe);
return false;
}
while (true)//接受多个用户
{
if(!mRMonitorServer.getboolRMonitorRunning())
{
return false;
}
try
{
if(mServerSocket != null)
{
mServerSocket.setSoTimeout(300);
mSocket = mServerSocket.accept();
mServerSocket.setSoTimeout(0);
}
else
return false;
}
catch(Exception timeoutE)
{
}
}
{
ServerSocket mServerSocket = new ServerSocket(localRPort,5);
}
catch(IOException Serverioe)
{
System.err.println("Cannot create ServerSocket error: " + Serverioe);
return false;
}
while (true)//接受多个用户
{
if(!mRMonitorServer.getboolRMonitorRunning())
{
return false;
}
try
{
if(mServerSocket != null)
{
mServerSocket.setSoTimeout(300);
mSocket = mServerSocket.accept();
mServerSocket.setSoTimeout(0);
}
else
return false;
}
catch(Exception timeoutE)
{
}
}