Extendscript Socket too slow
Hi guys,
I am building a jsx script which utilize the Socket object and posting data to my web server.
Currently I am reading bytes from an Image file (jpeg), converting the bytes to hexadecimal and sending them to the server as a JSON string (with several more parameters). In the server I am converting the hex back to binary and writing the bytes to a file.
So far, everything is working.
My problem is that it's taking too much time.
I did some tests:
A jpeg file 9KB is taking 5.5 seconds.
A jpeg file 532KB is taking 288 seconds (4.8 minutes).
Can someone explain to me why it's working so slow?
Maybe throw me an advice how the process can be speed up...
I am posting here my code (maybe it will help to figure out the bottleneck):
this.post = function(url, data, json){
var response = false, data = data || {}, json = json || false;
this.parseUrlParts(url);
data = (json)? this.stringify(data) : this.serialize(data);
this.socket.open(this.domain + ':' + this.port);
this.socket.timeout = 60;
this.socket.write("POST " + this.page + " HTTP/1.1\r\n");
this.socket.write("Host: " + this.domain + "\r\n");
this.socket.write("Content-Length: " + data.length + "\r\n");
if(json){
this.socket.write("Content-Type: application/json\r\n");
}
else {
this.socket.write("Content-Type: application/x-www-form-urlencoded\r\n");
}
this.socket.write("\r\n");
this.socket.write(data);
response = this.socket.read(64 * 1024);
this.socket.close();
response = response.split("\n\n");
response.splice(0,1);
return response.join("\n\n");
}
* I am not posting all the variables and methods here but it's not too hard to figure out what I am doing there.
