Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Keep old version

  • Loading branch information...
commit d47ded9b75711f5efa980ef1839c03c24659be03 1 parent 25fcf21
@wltsmrz wltsmrz authored
Showing with 41 additions and 8 deletions.
  1. +14 −0 competition/wsdemo-ws.js
  2. +27 −8 competition/wsdemo.js
View
14 competition/wsdemo-ws.js
@@ -0,0 +1,14 @@
+#!/usr/bin/env node
+
+var ws = require('ws')
+, wss = new ws.Server({port:8000})
+
+wss.on('connection', function(con) {
+
+ con.on('message', function() {
+
+ con.send.apply(this, arguments)
+
+ })
+
+})
View
35 competition/wsdemo.js
@@ -1,14 +1,33 @@
#!/usr/bin/env node
+var WebSocketServer = require("websocket").server;
+var http = require("http");
-var ws = require('ws')
-, wss = new ws.Server({port:8000})
+var server = http.createServer(function(request, response) {
+ response.writeHead(404);
+ response.end();
+});
-wss.on('connection', function(con) {
-
- con.on('message', function() {
+server.listen(8000, function() {
+ console.log((new Date()) + ' Server is listening on port 8000');
+});
- con.send.apply(this, arguments)
+wsServer = new WebSocketServer({
+ httpServer: server,
+ dropConnectionOnKeepaliveTimeout: false
+});
- })
+wsServer.on("request", function(request) {
+ var connection = request.accept(null, request.origin);
-})
+ connection.on("message", function(message) {
+ if (message.type === 'utf8') {
+ connection.sendUTF(message.utf8Data);
+ }
+ else if (message.type === 'binary') {
+ connection.sendBytes(message.binaryData);
+ }
+ });
+
+ connection.on('close', function(reasonCode, description) {
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.