Permalink
Browse files

Use ws module

  • Loading branch information...
1 parent 27c0149 commit 25fcf21f730bfc02dec2b65f48603851b9285ce2 @snowblindroan snowblindroan committed Jun 13, 2012
Showing with 8 additions and 27 deletions.
  1. +8 −27 competition/wsdemo.js
View
@@ -1,33 +1,14 @@
#!/usr/bin/env node
-var WebSocketServer = require("websocket").server;
-var http = require("http");
-var server = http.createServer(function(request, response) {
- response.writeHead(404);
- response.end();
-});
+var ws = require('ws')
+, wss = new ws.Server({port:8000})
-server.listen(8000, function() {
- console.log((new Date()) + ' Server is listening on port 8000');
-});
+wss.on('connection', function(con) {
+
+ con.on('message', function() {
-wsServer = new WebSocketServer({
- httpServer: server,
- dropConnectionOnKeepaliveTimeout: false
-});
+ con.send.apply(this, arguments)
-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) {
- });
-});
+})

0 comments on commit 25fcf21

Please sign in to comment.