Last active
September 17, 2015 21:16
-
-
Save rajanaresh/a1e856083ac36fa3487b to your computer and use it in GitHub Desktop.
SSL Certificate generation & websockets
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('key.pem'), | |
cert: fs.readFileSync('cert.pem') | |
}; | |
var app = require('https').createServer(options); | |
var io = require('socket.io')(app); | |
var queryfile = 'data.query'; | |
io.on('connection', function(socket) { | |
console.log('user connected'); | |
var fileHandler = function() { | |
fs.readFile(queryfile, 'utf8', function(error, data) { | |
if(error) { | |
console.log(error); | |
} | |
socket.emit('server', data); | |
}); | |
}; | |
fs.watchFile(queryfile, fileHandler); | |
socket.on('client', function(data) { | |
console.log(data); | |
}); | |
}); | |
app.listen(3000, function() { | |
console.log("listening on 3000"); | |
}); |
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 script = document.createElement('script'); | |
script.setAttribute('type', 'text/javascript'); | |
script.setAttribute('src', 'https://cdn.socket.io/socket.io-1.2.0.js'); | |
document.body.appendChild(script); | |
var socket = io.connect('http://localhost:3000'); | |
socket.on('server', function(data) { | |
console.log(data); | |
}); |
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
#http://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl | |
$> openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 1001 | |
// to avoid typing the password repeatedly do the following | |
$> openssl rsa -in key.pem -out newkey.pem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment