Hello there,
I am using Cocoa HTTPServer in iOS Application, where I have placed an HTML file in its root, so I am able to easily get that one using localhost:// ...
Up to this, everything is fine, I also have used WebSocket classes inside my application and have also implemented WebSockets on browser side too, so able to communicate with the application from HTML page.
I have placed a button inside that HTML that is calling a JS function
function previewFile() {
var preview = document.querySelector('img');
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
var rawData = new ArrayBuffer();
reader.onloadend = function () {
var stringContent = reader.result;
preview.src = stringContent;
ws.send("sendingFile");
var array = stringContent.match(/.{1,200}/g);
for (var i = 0; i < array.length; i++) {
ws.send(array[i]);
};
ws.send("END");
}
if (file) {
reader.readAsArrayBuffer(file);
} else {
preview.src = "";
}
}
This is working fine in case of Small sized file uploading, but Not working if the File size is bigger like 150KB or more..
One more weird case, This is also working fantastically if I open this HTML file in the browser of iPhone or iPad, but not working for Chrome/Safari of Mac. I tested this file with Node JS based server its working fine but having issue when Its connected with WebSocket server of iPhone using CocoaHTTPserver.
On every attempt of file uploading from this HTML to iPhone based server, Closes the Socket automatically everytime.
Please help me out, I am looking for this solution from last Week.
For iPhone side, I Have used the Demo Web socket sample's code provided with CocoaHTTPServer's source code.