io server to use with matthewmueller/io
npm install io-server
IO-server supports URL-based pooling. For example on the client-side:
IOconnect'/app/a/1' // gets events from sockets connected to: /app/a/1IOconnect'/app/a/2' // gets events from sockets connected to: /app/a/2IOconnect'/app/a' // gets all events from sockets connected to: /app/a/*IOconnect'/app/b' // gets events from sockets connected to: /app/bIOconnect'/app' // gets all events from sockets connected to: /app/*IOconnect'/' // gets all events from all sockets
For security purposes, you'll probably want to prevent clients from connecting to root.
Note: For pooling to work, you'll need to add the
express.querymiddleware before engine.io handles the request.
You can catch any event sent to the server by using
eson'connection' IOIOon'signup'jsonid = uid;thisemit'signup successful' json;
Authentication is delegated to the middleware level of express. You can stack authentication or validation middleware before engine.io handles the request.
/*** Module Dependencies*/var express = require'express'engine = require'engine.io'IO = require'io-server'app = expresses =server = require'http'createServerapp;/*** Handle the upgrade*/serveron'upgrade'eshandleUpgradereq socket head;;/*** Configuration*/appconfigureappuseexpresslogger'dev';appuseexpressquery;appuse'/engine.io' eshandleRequestbindes;appuseexpresserrorHandler;;/*** Handle the connection*/eson'connection' IO;/*** Bind to port*/serverlisten8080;console.log'Server started on port 8080';
Head over to io for tests.
(The MIT License)
Copyright (c) 2012 Matthew Mueller <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.