-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebsocket_Client_RX_TX.html
More file actions
executable file
·91 lines (79 loc) · 2.93 KB
/
Websocket_Client_RX_TX.html
File metadata and controls
executable file
·91 lines (79 loc) · 2.93 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<body>
<h1>WebSocket RX/TX Test Performance Tool</h1>
<script language="javascript" type="text/javascript">
var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
function TXconnect() {
if(!ipaddr.value.match(ipformat)){
alert("You have entered an invalid IP address!");
return false;
}
if((port.value > 65535)|| (port.value < 1)){
alert("You have entered an invalid Port number! (0<PortNum<65535)");
return false;
}
var wsurl="ws://"+ipaddr.value+":"+port.value;
ws = new WebSocket(wsurl);
//ws.binaryType = 'blob';
ws.binaryType = "arraybuffer";
ws.onopen = function(){
var reader = new FileReader();
var file = document.querySelector('input[type="file"]').files[0];
console.log(file);
reader.onload = function(event) {
var contents = event.target.result;
var byteArray = new Uint8Array(contents);
//console.log("byteArray: ",byteArray);
ws.send(byteArray);
//ws.close()
}
reader.readAsArrayBuffer(file);
};
ws.onerror = function() { alert("web socket error!"); };
ws.onmessage = function(e) {};
}
function RXconnect() {
if(!ipaddr.value.match(ipformat)){
alert("You have entered an invalid IP address!");
return false;
}
if((port.value > 65535)|| (port.value < 1)){
alert("You have entered an invalid Port number! (0<PortNum<65535)");
return false;
}
var wsurl="ws://"+ipaddr.value+":"+port.value;
ws = new WebSocket(wsurl);
ws.onopen = function(){};
ws.onerror = function() { alert("web socket error!"); };
ws.onmessage = function(e) {
var reader = new FileReader();
reader.onload = function(event) {
var contents = event.target.result;
webSocketPic.src=contents;
}
reader.readAsDataURL(e.data);
ws.send("amiok");
};
}
</script>
<table>
<font color="blue" font size="5">Step 1: Enter IP Address and Port</font>
<div>
<p><b>IP Address:</b><input value='192.168.0.164' type='text' id='ipaddr'/></p>
<p><b>Port:</b><input type='number' id='port' value="8888"/></p>
</div>
<div>
<font color="Red" font size="5">Step 2: Client(TX) send file to BMC(RX)</font>
<p><button onclick="TXconnect();">TX Connect to BMC</button></p>
<p><input type="file" id="input" name="myFiles"></p>
</div>
<div>
<font color="Red" font size="5">Step 2: Client(RX) receive file from BMC(TX)</font>
<p><tr><td><button onclick="RXconnect();">RX Connect BMC</button></td></tr></p>
<p><tr><td><img id="webSocketPic"></td></tr></p>
</div>
</table>
<p></p>
</body>
</html>