集册 Java实例教程 当一个非

当一个非

欢马劈雪     最近更新时间:2020-01-02 10:19:05

525
检测远程主机何时关闭非阻塞套接字


// Read from socket

int numBytesRead = socketChannel.read(buf);

/**
 * 时代Java公众号 - N o w J a  v a . c o m 提 供 
**/

if (numBytesRead == -1) {

    // No more bytes can be read from the channel

    socketChannel.close();

} else {

    // Read the bytes from the buffer

}


// Write to socket

int numBytesWritten = socketChannel.write(buf);