Permalink
Browse files

Test server moved out of the package.

  • Loading branch information...
1 parent 1f18155 commit d7fec4d9e189a4178093497bf5c5b67c8ecfcd83 @majek majek committed Aug 10, 2011
Showing with 4 additions and 99 deletions.
  1. +0 −6 config.js.example
  2. +1 −0 index.js
  3. +3 −2 package.json
  4. +0 −91 test-server.js
View
@@ -1,6 +0,0 @@
-exports.sockjs_opts = {
- sockjs_url: "http://127.0.0.1:8000/lib/sockjs.js"
-};
-
-exports.port = 9999
-exports.host = "0.0.0.0"
View
@@ -0,0 +1 @@
+module.exports = require('./lib/sockjs');
View
@@ -1,9 +1,10 @@
{
- "name": "sockjs-node",
+ "name": "sockjs",
"version": "0.0.1",
"dependencies": {
"coffee-script": "1.1.1",
"jquery": "1.5.1",
"node-uuid": "1.2.0"
- }
+ },
+ "main": "index"
}
View
@@ -1,91 +0,0 @@
-var http = require('http');
-var url = require('url');
-
-var sockjs = require('./lib/sockjs');
-
-var config = require('./config');
-console.log(" [*] config:", config.sockjs_opts);
-
-var sjs_echo = new sockjs.Server(config.sockjs_opts);
-sjs_echo.on('open', function(conn){
- console.log(' [+] echo open ' + conn);
- conn.on('close', function(e) {
- console.log(' [-] echo close ' + conn, e);
- });
- conn.on('message', function(e) {
- var d = JSON.stringify(e.data);
- console.log(' [ ] echo message ' + conn,
- d.slice(0,64)+
- ((d.length > 64) ? '...' : ''));
- conn.send(e.data);
- });
-});
-
-var sjs_close = new sockjs.Server(config.sockjs_opts);
-sjs_close.on('open', function(conn){
- console.log(' [+] clos open ' + conn);
- conn.close(3000, "Go away!");
- conn.on('close', function(e) {
- console.log(' [-] clos close ' + conn, e);
- });
- });
-
-var sjs_ticker = new sockjs.Server(config.sockjs_opts);
-sjs_ticker.on('open', function(conn){
- console.log(' [+] ticker open ' + conn);
- var tref;
- var schedule = function() {
- conn.send('tick!');
- tref = setTimeout(schedule, 1000);
- };
- tref = setTimeout(schedule, 1000);
- conn.on('close', function(e) {
- clearTimeout(tref);
- console.log(' [-] ticker close ' + conn, e);
- });
-});
-
-var broadcast = {};
-var sjs_broadcast = new sockjs.Server(config.sockjs_opts);
-sjs_broadcast.on('open', function(conn){
- console.log(' [+] broadcast open ' + conn);
- broadcast[conn.id] = conn;
- conn.on('close', function(e) {
- delete broadcast[conn.id];
- console.log(' [-] broadcast close' + conn, e);
- });
- conn.on('message', function(e) {
- console.log(' [-] broadcast message', e);
- for(var id in broadcast) {
- broadcast[id].send(e.data);
- }
- });
-});
-
-
-var default_handler = function(req, res) {
- res.statusCode = 404;
- if (url.parse(req.url).pathname === '/500_error') {
- res.statusCode = 500;
- }
- console.log(res.statusCode, req.url);
- if (res.writeHead) {
- res.writeHead(res.statusCode);
- res.end("Error");
- } else{
- res.end();
- }
-};
-
-console.log(" [*] Listening on", config.host +':'+config.port);
-var server = http.createServer();
-server.addListener('request', default_handler);
-server.addListener('upgrade', default_handler);
-
-
-sjs_echo.installHandlers(server, {prefix:'[/]echo'});
-sjs_close.installHandlers(server, {prefix:'[/]close'});
-sjs_ticker.installHandlers(server, {prefix:'[/]ticker'});
-sjs_broadcast.installHandlers(server, {prefix:'[/]broadcast'});
-
-server.listen(config.port, config.host);

0 comments on commit d7fec4d

Please sign in to comment.