Copy link to clipboard
Copied
Part of our program includes an email client. Recently I started trying to use the SecureSocket feature of AIR 2 to send mail. Everything works fine if the total number of bytes sent is 130k, but at 140k or above something bad happens. The writebytes command completes but either all of the data is not sent, or it is getting corrupted. To write the bytes to the securesocket we just do this:
mailBodyBytes.position = 0;
var bytes:Number = mailBodyBytes.bytesAvailable;
writeBytes(mailBodyBytes, 0, bytes);
flush();
You can send huge files 500k or more when using sockets and not SecureSockets with this same code. I've also tried many modifications to the above code including writing smaller chunks with flush in between them, and writing in one byte at a time. I've also tried this across three different smtp servers with the same results. I'm listening for all the events the socket class fires but none of them are going off. Basically above 130k things just seem to get stuck.
I'm hoping a dev or someone who's done this before might have some advice.
Thank you,
-Eric
**Update
So I added a delay, now my code writes 100,000 bytes inside a five second window and calls flush afterwards. Now it works, but this strikes me as a very bad solution. For one I'm hacking around some internal problem. Two it seems that flush must be non-blocking which is good in some cases but very bad in others. Finally I feel like my five second timer approach is dependant on the upstream connection speed. If it were slower I'm sure it would break again. It feels like there needs to be some better flow control here for SecureSockets.
New Code Below
private function sendMailToServer():void{
/*
mailBodyBytes.position = 0;
var bytes:Number = mailBodyBytes.bytesAvailable;
writeBytes(mailBodyBytes, 0, bytes);
//writeUTFBytes ("\r\n.\r\n");
flush();
if (_close == false)
flush();*/
Logger.debug(mailBodyBytes.toString());
this.sendTimer = new Timer(5000);
this.sendTimer.addEventListener(TimerEvent.TIMER, onSendTimer);
mailBodyBytes.position = 0;
this.sendTimer.start();
}
private function onSendTimer(event:TimerEvent):void
{
if(mailBodyBytes.bytesAvailable >= 100000){
writeBytes(mailBodyBytes, mailBodyBytes.position, 100000);
flush();
mailBodyBytes.position = mailBodyBytes.position + 100000;
}else if(mailBodyBytes.bytesAvailable > 0){
writeBytes(mailBodyBytes, mailBodyBytes.position);
flush();
this.sendTimer.stop();
}else{
this.sendTimer.stop();
}
}
Copy link to clipboard
Copied
Hello,
Thanks for bringing this up. We'll investigate and get back to you shortly.
I've moved the thread to the Problems & Bugs forum.
Chris
Copy link to clipboard
Copied
Can you please specify on what platform(s) you are seeing this problem?
Thanks!
Copy link to clipboard
Copied
Sure OSX Snow Leopard 10.6.4, Mac Book Pro.