TcpListener.pending替代java

时间:2013-02-02 12:09:08

标签: java sockets

Hello..iknow在c#中你可以使用bool来检查服务器是否有挂起连接.pending();但有没有办法在java中这样做?即时通讯问因为我无法在网上找到任何相关内容...谢谢 iwanna就像:

ServerSocket srv=new ServerSocket(port);
if(srv.isPending())//How this can be done????
{
Socket Cl=srv.accept();
while(Cl.isConnected())
{
//read packet stream..........
}
}

1 个答案:

答案 0 :(得分:0)

java中没有这样的方法。你必须编写一个无限循环来等待这样的客户端连接。

ServerSocket srv=new ServerSocket(port);
while(true){
   /*Program will wait for a new client connection
     at this line and then proceeds further*/
   Socket client=srv.accept();
   // Rest of the code will continue here
}