-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (70 loc) · 1.83 KB
/
index.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var wolfram = require('wolfram-alpha').createClient("4GJ2YK-Q4QLHV8XPV");
var os = require('os');
var ifaces = os.networkInterfaces();
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
console.log("Your ip address is:");
Object.keys(ifaces).forEach(function (ifname) {
var alias = 0;
ifaces[ifname].forEach(function (iface) {
if ('IPv4' !== iface.family || iface.internal !== false) {
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return;
}
if (alias >= 1) {
// this single interface has multiple ipv4 addresses
console.log(ifname + ':' + alias, iface.address);
} else {
// this interface has only one ipv4 adress
console.log(ifname, iface.address);
}
++alias;
});
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
wolfram.query(msg, function (err, result) {
k = 0;
if (err) throw err;
x = JSON.stringify(result, null, 2);
io.emit('chat message', msg);
for (var i = 0; i<x.length; i++){
if(x[i]=='t'){
i++;
if(!(x[i]=='i'||x[i]=='e'))
continue;
y="t"+x[i];
i++;
if(!(x[i]=='t'||x[i]=='x'))
continue;
while(x[i]!='\n'){
if(x[i]!='"'&&x[i]!=',')
y+=x[i];
else if(x[i]=='"')
y+=' ';
i++;
k++;
}
console.log(y);
if(k == 1)
msg = msg + y;
else
msg = y;
io.emit('chat message', msg );
}
}
});
console.log('message: ' + msg);
});
socket.on('chat message1', function(msg){
io.emit('chat message1', msg );
console.log('message: ' + msg);
});
});
http.listen(3000, function(){
console.log('listening on port:3000');
});