I am currently testing a WebSocket on localhost using Java and JavaScript. I am running Tomcat 7.0.42 with no proxy in between. The WebSocket works fine when sending text and small images, but the connection is forcibly closed on the client side (Chrome browser) when attempting to send a large photo. It's worth noting that the 'onClose' callback in MessageInbound on Tomcat is not triggered after the WebSocket in the browser closes the connection.
Is there a solution to this issue? Thank you.
You can view the captured data from Chrome Developer Tools here
Below is the code snippet from the client-side:
for (var i = 0, f; f = files[i]; i++) {
// Step 1: Notify the server about the intended recipient
ws.send(JSON.stringify({
action: "binary",
receiver: <%=selectedfriend.getUserId()%>,
timestamp: new Date().getTime()
}));
// Step 2: Send the file
ws.send(f);
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var span = document.createElement('span');
span.innerHTML = ['<img class="thumb" style="width: 50px;height: 30px;" src="', e.target.result,
'" title="', escape(theFile.name), '"/>'].join('');
appendImage(span.innerHTML, "pullleft");
};
})(f);
reader.readAsDataURL(f);
}