aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/jabber/ws/WSConnections.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-16 16:43:43 +0300
committerGravatar Vitaly Takmazov2016-01-16 16:43:43 +0300
commite746ca6970bea80ec9b5ae79dda8f6332254e301 (patch)
tree92c354060fa03c5f781804ba1e38114a0a8af45c /src/main/java/com/juick/jabber/ws/WSConnections.java
parent694bc7b9dd4f3e7d0a918ddb2327dbb676fc6465 (diff)
moved to Gradle
Diffstat (limited to 'src/main/java/com/juick/jabber/ws/WSConnections.java')
-rw-r--r--src/main/java/com/juick/jabber/ws/WSConnections.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/java/com/juick/jabber/ws/WSConnections.java b/src/main/java/com/juick/jabber/ws/WSConnections.java
new file mode 100644
index 00000000..15fbe4e8
--- /dev/null
+++ b/src/main/java/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();
+ sChannel.configureBlocking(false);
+ sChannel.register(sel, SelectionKey.OP_READ);
+ System.out.println(sChannel.socket().getRemoteSocketAddress().toString() + " ACCEPTED");
+ }
+ }
+ } catch (Exception e) {
+ System.err.println("WSConnections: " + e);
+ }
+ }
+}