有什么办法可以从 C++ 传输数据吗? Flex/Air 比插座更快?

发布于 2025-01-01 04:07:51 字数 1024 浏览 1 评论 0原文

我有一个 C++ 应用程序,它通过 TCP 套接字将图像发送到 Flex/Air 前端。所有这些数据传输都发生在同一主机中,因此套接字连接到本地主机服务器。

问题是 Flex/Air 需要很长时间才能从插槽读取整个图像。服务器发送图像的速度相当快,但 Flex/Air 会以很小的部分读取该图像。整个图像大约有 300MB,Flex/AIR 每次迭代仅读取大约 1KB。因此,flex 不断调用套接字数据回调,这导致应用程序变慢。

是否有任何同步套接字可以与flex一起使用,或者某种可以一次读取整个数据的套接字?如果套接字不是最佳选择,还有其他更快的选择吗?

我的套接字类如下所示:

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 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
        }           
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕色琉璃 2025-01-08 04:07:51

我会使用 AIR 原生扩展。这提供了一个接口,以便您可以直接在 C++ 和 AS3 之间发送数据。它肯定会更快,但您需要以 AIR 3.0 为目标,并且需要为代码运行的每个平台创建一个扩展。

I would use Native Extensions for AIR. This provides an interface so that you can send data directly between C++ and AS3. It will definitely be faster, but you need to target AIR 3.0, and you need to create an extension for each platform your code is running on.

孤芳又自赏 2025-01-08 04:07:51

我认为如果可能的话你需要改变你的解决方案。你需要一个http服务器来托管你的图像,并将图像的文件名(或url)发送到Flex前端,然后你可以通过URLLoader加载它们,并且只监听“完成”事件。

我确信这会更快;o) 这个解决方案适用吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文