代码拉取完成,页面将自动刷新
package blocking;
import util.Logger;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
/**
* Created by huangyinhuang on 1/31/2018.
*/
public class BlockingNioServer {
public static void main(String[] args) throws Exception {
// please note: configure channel blocking state as true
ServerSocketChannel server = ServerSocketChannel.open();
server.configureBlocking(true);
Logger.info("A server is started on port 9000");
ServerSocket serverSocket = server.socket();
serverSocket.bind(new InetSocketAddress(9000));
// please note: server.accept() will block current thread
Logger.info("Server is waiting for client connection, current thread is blocking...");
SocketChannel channel = server.accept();
Logger.printClientInfo(channel);
Logger.info("Is connected: " + channel.isConnected());
channel.close();
server.close();
Logger.info("the end");
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。