-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (35 loc) · 937 Bytes
/
index.js
File metadata and controls
43 lines (35 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var NodeRSA = require('node-rsa');
var users = [];
function handler (req, res) {
fs.readFile("http://localhost:8000/templates/rsa.html",
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.on('connection', function(socket){
console.log('a user connected');
socket.on("new_user",function(data){
console.log("DATA: ", data);
users.push(data);
socket.emit("connected_users",users);
});
socket.on("cypher_message",function(data){
console.log("Message: ",data);
socket.emit("message", data);
console.log("emitio");
});
});
app.listen(3000, function(){
console.log('listening on *:3000');
});
io.on('disconnect', function(){
console.log("Bye BYe");
});