-
-
Save identityclash/fefa84725c51eb5168a8 to your computer and use it in GitHub Desktop.
Basic sockjs server and with ssl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sockjs = require('sockjs'); | |
| var server = require('http').Server(); | |
| var socket = sockjs.createServer({sockjs_url: 'https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/0.3.4/sockjs.min.js'}); | |
| socket.on('connection', function (conn) { | |
| console.log('new connection id:' + conn.id); | |
| conn.on('close', function () { | |
| console.log('connection closed id:' + conn.id); | |
| }); | |
| conn.on('data', function (data) { | |
| console.log('data:' + data); | |
| conn.write('received:' + data); | |
| }); | |
| }); | |
| socket.installHandlers(server, {prefix: '/sockjs'}); | |
| server.listen(80); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fs = require("fs"); | |
| var options = { | |
| key: fs.readFileSync('ssl.key'), | |
| cert: fs.readFileSync('ssl.crt') | |
| }; | |
| var sockjs = require('sockjs'); | |
| var server = require('https').Server(options); | |
| var socket = sockjs.createServer({sockjs_url: 'https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/0.3.4/sockjs.min.js'}); | |
| socket.on('connection', function (conn) { | |
| console.log('new connection id:' + conn.id); | |
| console.log(conn); | |
| conn.on('close', function () { | |
| console.log('connection closed id:' + conn.id); | |
| }); | |
| conn.on('data', function (data) { | |
| console.log('data:' + data); | |
| conn.write('received:' + data); | |
| }); | |
| }); | |
| socket.installHandlers(server, {prefix: '/sockjs'}); | |
| server.listen(443); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "sockjs-server", | |
| "version": "0.0.0-unreleasable", | |
| "dependencies": { | |
| "sockjs": "0.3.x" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment