![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e177. Creating a Non-Blocking Server SocketThis example shows how to create a non-blocking server socket. A non-blocking server socket requires a server socket channel.See also e179 Using a Selector to Manage Non-Blocking Server Sockets. // Create a non-blocking server socket and check for connections try { // Create a non-blocking server socket channel on port 80 ServerSocketChannel ssChannel = ServerSocketChannel.open(); ssChannel.configureBlocking(false); int port = 80; ssChannel.socket().bind(new InetSocketAddress(port)); // See e178 Accepting a Connection on a ServerSocketChannel // for an example of accepting a connection request } catch (IOException e) { }
e174. Reading from a SocketChannel e175. Writing to a SocketChannel e176. Using a Selector to Manage Non-Blocking Sockets e178. Accepting a Connection on a ServerSocketChannel e179. Using a Selector to Manage Non-Blocking Server Sockets e180. Detecting When a Non-Blocking Socket Is Closed by the Remote Host
© 2002 Addison-Wesley. |