import java.net.InetSocketAddress; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import org.junit.Test; public class ServerSocketChannelTest { @Test public void testListen() throws Exception{ ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.socket().bind(new InetSocketAddress(9999)); serverSocketChannel.configureBlocking(false); while(true){ SocketChannel socketChannel = serverSocketChannel.accept(); if(socketChannel != null){ //do something with socketChannel... } } } }
ServerSocketChannel
猜你喜欢
转载自allen-huang.iteye.com/blog/2275938
今日推荐
周排行