var
ws =
new
WebSocket(
"ws://localhost:8080/msg"
);
ws.onopen =
function
(evt) {
console.log(
"Connection open ..."
);
ws.send(
"Hello WebSockets!"
);
};
ws.onmessage =
function
(event) {
if
(
typeof
event.data === String) {
console.log(
"Received data string"
);
}
if
(event.data
instanceof
ArrayBuffer) {
var
buffer = event.data;
console.log(
"Received arraybuffer"
);
}
console.log(
"Received Message: "
+ evt.data);
ws.close();
};
ws.onclose =
function
(evt) {
console.log(
"Connection closed."
);
};
ws.send(
"Hello WebSockets!"
);
var
file = document
.querySelector(
'input[type="file"]'
)
.files[0];
ws.send(file);
var
img = canvas_context.getImageData(0, 0, 400, 320);
var
binary =
new
Uint8Array(img.data.length);
for
(
var
i = 0; i < img.data.length; i++) {
binary[i] = img.data[i];
}
ws.send(binary.buffer);
var
data =
new
ArrayBuffer(10000000);
socket.send(data);
if
(socket.bufferedAmount === 0) {
}
else
{
}
ws.onerror =
function
(event) {
};
es.addEventListener(
"error"
,
function
(event) {
});