-
Notifications
You must be signed in to change notification settings - Fork 1
/
serv1.js
36 lines (36 loc) · 1.19 KB
/
serv1.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
var a,b,c;
var WebSocket = require("ws");
var wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
var object = JSON.parse(message).object;
console.log("server 1 starts working on a task (" + object.N + ")");
a = 0;
b = 0;
c = 0;
for (let i = 0; i<object.N; ++i)
{
let previous = 0;
if (i != 0)
{
previous = Math.floor(100*(i-1)/object.N);
}
let current = Math.floor(100*i/object.N);
if (current > previous)
{
ws.send(JSON.stringify({id : object.Id, status : "progress", progress : Math.floor(i*100/object.N)}));
}
for (let j = 0; j<object.N; ++j)
{
for(let k = 0; k<object.N; ++k)
{
c+= j*k+i/2;
b+=c*j;
a= b-c;
}
}
}
console.log("server 1 completed working on a task");
ws.send(JSON.stringify({id : object.Id, status : "result", result : [object.N, a, b, c]}));
});
});