I have a C++ application which sends images to a Flex/Air front-end via TCP sockets. All this data transfer occur in the same host, so the socket connects to a localhost server.
The problem is that the Flex/Air takes a really long time to read the entire image from the socket. The server sends the image quite fast, but the Flex/Air reads this image in tiny parts. The whole image has about 300MB and the Flex/AIR reads only about 1KB each iteration. So the flex keeps calling the socket data callback, which is causing the application to slowdown.
Is there any synchronous sockets to use with flex, or some kind of socket which can read the entire data all at once? If sockets aren’t the best choice, is there any other faster options?
My socket class looks like this:
public class ClientSocket extends Socket
{
public function ClientSocket(host:String, port:int)
{
super();
addListeners();
...
this.endian = Endian.LITTLE_ENDIAN;
}
private function addListeners():void
{
...
addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
...
}
private function onSocketData(event:ProgressEvent):void
{
try
{
...
var serverMessage:ByteArray = new ByteArray;
readBytes(serverMessage);
...
}
catch(error:Error)
{
//Error handling
}
}
}
I think you need to change your solution if possible. You need a http server to host your images, and send the images’ filename(or url) to Flex front-end, then you can load them by URLLoader and only listen on “complete” event.
I’m sure this will be faster ;o) Is this solution appliable?