diff options
author | Ugnich Anton | 2013-08-04 02:50:44 +0700 |
---|---|---|
committer | Ugnich Anton | 2013-08-04 02:50:44 +0700 |
commit | db2d48c068715c2841fd60b955c98580236c400d (patch) | |
tree | 200df4736f27f978b770e6e23fac87a5ebbb5a70 /src/com/juick/jabber/ws/WSConnections.java | |
parent | 44c7c01059640147fbb9df129c2cff7b0a127329 (diff) |
4 threads
Diffstat (limited to 'src/com/juick/jabber/ws/WSConnections.java')
-rw-r--r-- | src/com/juick/jabber/ws/WSConnections.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/com/juick/jabber/ws/WSConnections.java b/src/com/juick/jabber/ws/WSConnections.java new file mode 100644 index 00000000..020442f7 --- /dev/null +++ b/src/com/juick/jabber/ws/WSConnections.java @@ -0,0 +1,44 @@ +package com.juick.jabber.ws; + +import java.net.InetSocketAddress; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.util.Iterator; + +/** + * + * @author ugnich + */ +public class WSConnections implements Runnable { + + Selector sel; + + @Override + public void run() { + try { + sel = Selector.open(); + ServerSocketChannel listensock = ServerSocketChannel.open(); + listensock.configureBlocking(false); + listensock.socket().bind(new InetSocketAddress(8081)); + listensock.register(sel, SelectionKey.OP_ACCEPT); + + while (true) { + sel.select(); + Iterator<SelectionKey> it = sel.selectedKeys().iterator(); + while (it.hasNext()) { + SelectionKey selKey = it.next(); + it.remove(); + ServerSocketChannel ssChannel = (ServerSocketChannel) selKey.channel(); + SocketChannel sChannel = ssChannel.accept(); + System.out.println(sChannel.socket().getRemoteSocketAddress().toString() + " ACCEPTED"); + sChannel.configureBlocking(false); + sChannel.register(WSData.sel, SelectionKey.OP_READ); + } + } + } catch (Exception e) { + System.err.println("WSConnections: " + e); + } + } +} |