-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser-client.html
65 lines (58 loc) · 1.68 KB
/
browser-client.html
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
<html>
<head></head>
<body></body>
<script type="text/javascript">
/**
* Initialization
*/
var Size = 1048576; // 1GiB
var MaxIter = 20;
/**
* WevSocketClient connect
*/
//var ServerName = 'server.info';
var ServerName = 'localhost';
var PortN = 8082
var ws = new WebSocket('ws://' + ServerName + ':' + PortN);
ws.binaryType = 'arraybuffer';
ws.onopen = function() {
var start = undefined;
var totalTime = 0;
var i = MaxIter;
/**
* Download Event
*/
ws.onmessage = function(message) {
var time = Date.now() - start;
//*console.log(message);
console.log('Data size: ' + Size + ', roudtrip time: ' + time + ' ms');
totalTime += time;
if (--i) {
uploadStart(Size);
} else {
var ave = totalTime / MaxIter;
console.log('Average roundtrip time: ' + ave + ' ms');
/**
* Transfer ratio: Size(Bytes) / (ave(ms) / 2(roundtrip)) * 1000 = (Bytes per Second)
* (Bytes per Second) * 8 / 1024 / 1024= (Mbps)
*/
console.log('Transfer ratio: ' + (Size / ave * 2000).toFixed(1) + '[Bytes per Second] = ' + (Size / ave * 0.0152587890625).toFixed(1) + '[Mbps]');
}
};
/**
* Upload File
*/
function uploadStart(size) {
var byteArray = new Uint8Array(size);
//for (var j = 0; j < size; j++) {
// byteArray[j] = 0x55;
//}
var buf = byteArray.buffer;
//*console.log(buf);
start = Date.now();
ws.send(buf);
}
uploadStart(Size);
};
</script>
</html>