Adobe AIR HTTP 连接限制

发布于 2024-12-08 03:39:26 字数 2388 浏览 1 评论 0原文

我正在开发一个 Adob​​e AIR 应用程序,它可以将文件上传到运行 Apache 和 PHP 的 Web 服务器。可以同时上传多个文件,应用程序还可以调用 Web 服务器来执行各种 API 请求。

我遇到的问题是,如果我开始两个文件上传,当它们正在进行时,任何其他 HTTP 请求都会超时,从用户的角度来看,这会导致应用程序出现问题。

Adobe AIR 应用程序是否仅限于 2 个 HTTP 连接,还是可能存在其他问题? 通过搜索这个问题,我没有发现太多,但一篇文章确实表明它不仅限于两个连接。

文件上传是通过调用 File 类的 upload 方法来执行的,API 调用是使用 HTTPService 类来完成的。我使用的开发 Web 服务器是 WAMP 服务器,但是当应用程序发布时,它将与 LAMP 服务器通信。

谢谢, 以下

是我用来上传文件的代码:

protected function btnAddFile_clickHandler(event:MouseEvent):void
{
    // Create a new File object and display the browse file dialog
    var uploadFile:File = new File();
    uploadFile.browseForOpen("Select File to Upload");
    uploadFile.addEventListener(Event.SELECT, uploadFile_SelectedHandler);
}

private function uploadFile_SelectedHandler(event:Event):void
{
    // Get the File object which was used to select the file
    var uploadFile:File = event.target as File;
    uploadFile.addEventListener(ProgressEvent.PROGRESS, file_progressHandler);
    uploadFile.addEventListener(IOErrorEvent.IO_ERROR, file_ioErrorHandler);
    uploadFile.addEventListener(Event.COMPLETE, file_completeHandler);

    // Create the request URL based on the download URL
    var requestURL:URLRequest = new URLRequest(AppEnvironment.instance.serverHostname + "upload.php");
    requestURL.method = URLRequestMethod.POST;

    // Set the post parameters
    var params:URLVariables = new URLVariables(); 
    params.name = "filename.ext";
    requestURL.data = params;

    // Start uploading the file to the server
    uploadFile.upload(requestURL, "file");
}

以下是 API 调用的代码:

private function sendHTTPPost(apiFile:String, postParams:Object, resultCallback:Function, initialCallerResultCallback:Function):void
{
    var httpService:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
    httpService.url = AppEnvironment.instance.serverHostname + apiFile;
    httpService.method = "POST";
    httpService.requestTimeout = 10;
    httpService.resultFormat = HTTPService.RESULT_FORMAT_TEXT;
    httpService.addEventListener("result", resultCallback);
    httpService.addEventListener("fault", httpFault);
    var token:AsyncToken = httpService.send(postParams);

    // Add the initial caller's result callback function to the token
    token.initialCallerResultCallback = initialCallerResultCallback;
}

I'm working on an Adobe AIR application which can upload files to a web server, which is running Apache and PHP. Several files can be uploaded at the same time and the application also calls the web server for various API requests.

The problem I'm having is that if I start two file uploads, while they are in progress any other HTTP requests will time out, which is causing a problem for the application and from a user point of view.

Are Adobe AIR applications limited to 2 HTTP connections, or is something else probably the issue?
From searching about this issue I've not found much but one article did indicated that it wasn't limited to just two connections.

The file uploads are performed by calling the File classes upload method, and the API calls are done using the HTTPService class. The development web server I am using is a WAMP server, however when the application is released it will be talking to a LAMP server.

Thanks,
Grant

Here is the code I'm using to upload the file:

protected function btnAddFile_clickHandler(event:MouseEvent):void
{
    // Create a new File object and display the browse file dialog
    var uploadFile:File = new File();
    uploadFile.browseForOpen("Select File to Upload");
    uploadFile.addEventListener(Event.SELECT, uploadFile_SelectedHandler);
}

private function uploadFile_SelectedHandler(event:Event):void
{
    // Get the File object which was used to select the file
    var uploadFile:File = event.target as File;
    uploadFile.addEventListener(ProgressEvent.PROGRESS, file_progressHandler);
    uploadFile.addEventListener(IOErrorEvent.IO_ERROR, file_ioErrorHandler);
    uploadFile.addEventListener(Event.COMPLETE, file_completeHandler);

    // Create the request URL based on the download URL
    var requestURL:URLRequest = new URLRequest(AppEnvironment.instance.serverHostname + "upload.php");
    requestURL.method = URLRequestMethod.POST;

    // Set the post parameters
    var params:URLVariables = new URLVariables(); 
    params.name = "filename.ext";
    requestURL.data = params;

    // Start uploading the file to the server
    uploadFile.upload(requestURL, "file");
}

Here is the code for the API calls:

private function sendHTTPPost(apiFile:String, postParams:Object, resultCallback:Function, initialCallerResultCallback:Function):void
{
    var httpService:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
    httpService.url = AppEnvironment.instance.serverHostname + apiFile;
    httpService.method = "POST";
    httpService.requestTimeout = 10;
    httpService.resultFormat = HTTPService.RESULT_FORMAT_TEXT;
    httpService.addEventListener("result", resultCallback);
    httpService.addEventListener("fault", httpFault);
    var token:AsyncToken = httpService.send(postParams);

    // Add the initial caller's result callback function to the token
    token.initialCallerResultCallback = initialCallerResultCallback;
}

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

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

发布评论

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

评论(3

饭团 2024-12-15 03:39:26

如果您使用的是 Windows 系统,Adobe AIR 将使用 Microsoft 的 WinINet 库 访问网络。默认情况下,此库将与单个服务器的并发连接数限制为 2 :

WinInet 限制它与单个 HTTP 服务器建立的同时连接数。如果超过此限制,请求将被阻止,直到当前连接之一完成。这是设计使然,并且符合 HTTP 规范和行业标准。

...与单个 HTTP 1.1 服务器的连接仅限于两个同时连接

有一个 API 可以更改此限制的值,但我不知道是否可以从 AIR 访问它。

由于此限制还会影响网站的页面加载速度,因此某些网站对图像、JavaScript 和样式表等工件使用多个 DNS 名称,以允许浏览器打开更多并行连接。

因此,如果您控制服务器部分,解决方法可能是创建 DNS 别名,例如用于上传的 www.example.com 和用于 API 请求的 api.example.com

If you are on a windows system, Adobe AIR is using Microsofts WinINet library to access the web. This library by default limits the number of concurrent connections to a single server to 2:

WinInet limits the number of simultaneous connections that it makes to a single HTTP server. If you exceed this limit, the requests block until one of the current connections has completed. This is by design and is in agreement with the HTTP specification and industry standards.

... Connections to a single HTTP 1.1 server are limited to two simultaneous connections

There is an API to change the value of this limit but I don't know if it is accessible from AIR.

Since this limit also affects page loading speed for web sites, some sites are using multiple DNS names for artifacts such as images, javascripts and stylesheets to allow a browser to open more parallel connections.

So if you are controlling the server part, a workaround could be to create DNS aliases like www.example.com for uploads and api.example.com for API requests.

蘑菇王子 2024-12-15 03:39:26

因此,当我研究这个问题时,我在文档中发现了有关使用 File.upload() 的信息:

开始将文件上传到远程服务器。虽然 Flash Player 对上传或下载的文件大小没有限制,但该播放器官方支持上传或下载最大为 100 MB 的文件。调用此方法之前,必须先调用 FileReference.browse() 或 FileReferenceList.browse() 方法。

侦听器接收事件来指示上传的进度、成功或失败。虽然可以使用FileReferenceList对象让用户选择多个文件进行上传,但是必须将文件逐个上传;为此,请迭代 FileReference 对象的 FileReferenceList.fileList 数组。

FileReference.upload() 和 FileReference.download() 函数是
非阻塞。这些函数在调用之后、调用之前返回
文件传输完成。另外,如果 FileReference
对象超出范围,任何尚未上传或下载的对象
离开范围后,对该对象完成的操作将被取消。务必
只要您的 FileReference 对象保留在范围内
上传或下载预计将继续。

我想知道上传多个文件时是否会出现问题。我发现您正在使用 browserForOpen() 而不是 browser()。看起来他们可能会做同样的事情......但也许不是。

我还在 File 类文档中看到了这一点

请注意,由于 Flash Player 中添加了新功能,因此在发布到 Flash Player 10 时,您一次只能激活以下操作之一:FileReference.browse()、FileReference.upload()、FileReference。下载(),FileReference.load(),FileReference.save()。否则,Flash Player 将引发运行时错误(代码 2174)。使用 FileReference.cancel() 停止正在进行的操作。此限制仅适用于 Flash Player 10。以前版本的 Flash Player 不受此同时进行多个操作的限制的影响。

当您说允许用户上传多个文件时,您是指对 browser() 和 upload() 的后续调用,还是指包含多个文件的一次调用?看来,如果您尝试进行多个单独的调用,这可能是一个问题。

无论如何,我不知道这是否有很大帮助。看来您正在尝试做的事情应该是可能的。我只能猜测,问题可能出在执行上。祝你好运:)

参考:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#upload()

http://help.adobe .com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#browse()

So as I was looking into this, I came across this info about using File.upload() in the documentation:

Starts the upload of the file to a remote server. Although Flash Player has no restriction on the size of files you can upload or download, the player officially supports uploads or downloads of up to 100 MB. You must call the FileReference.browse() or FileReferenceList.browse() method before you call this method.

Listeners receive events to indicate the progress, success, or failure of the upload. Although you can use the FileReferenceList object to let users select multiple files for upload, you must upload the files one by one; to do so, iterate through the FileReferenceList.fileList array of FileReference objects.

The FileReference.upload() and FileReference.download() functions are
nonblocking. These functions return after they are called, before the
file transmission is complete. In addition, if the FileReference
object goes out of scope, any upload or download that is not yet
completed on that object is canceled upon leaving the scope. Be sure
that your FileReference object remains in scope for as long as the
upload or download is expected to continue.

I wonder if something there could be giving you issues with uploading multiple files. I see that you are using browserForOpen() instead of browse(). It seems like the probably do the same thing... but maybe not.

I also saw this in the File class documentation

Note that because of new functionality added to the Flash Player, when publishing to Flash Player 10, you can have only one of the following operations active at one time: FileReference.browse(), FileReference.upload(), FileReference.download(), FileReference.load(), FileReference.save(). Otherwise, Flash Player throws a runtime error (code 2174). Use FileReference.cancel() to stop an operation in progress. This restriction applies only to Flash Player 10. Previous versions of Flash Player are unaffected by this restriction on simultaneous multiple operations.

When you say that you let users upload multiple files, do you mean subsequent calls to browse() and upload() or do you mean one call that includes multiple files? It seems that if you are trying to do multiple separate calls that that may be an issue.

Anyway, I don't know if this is much help. It definitely seems that what you are trying to do should be possible. I can only guess that what is going wrong is perhaps a problem with implementation. Good luck :)

Reference: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#upload()

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#browse()

陌路黄昏 2024-12-15 03:39:26

仅仅因为我正在考虑一个非常相似的问题,因为我的一个实际应用程序出现错误,所以我决定写下我找到的答案。

我实例化了11

Http连接

并想知道为什么我的 Flex 4 应用程序停止工作并抛出 HTTP 错误,尽管它以前工作得很好,只有 5 个同时的 HttpConnections 到同一台服务器。

我自己对此进行了测试,因为我在 Flex 文档或互联网上没有找到任何与此相关的内容。

我发现使用超过 5 个 HTTPConnections 是 Fl​​ex 应用程序抛出运行时错误的原因。

我决定一个接一个地实例化连接,作为一种临时解决方法:在另一个连接接收到数据后加载下一个连接,依此类推。
当然,这只是暂时的,因为接下来的步骤之一将是更改响应服务器代码,使其应答包含在一次响应中对多个表的请求结果的请求。当然,客户端应用程序逻辑也需要更改。

Just because I was thinking about a very similar question because of an error in one of my actual apps, I decided to write down the answer I found.

I instantiated 11

HttpConnections

and was wondering why my Flex 4 Application stopped working and threw an HTTP-Error although it was working pretty good formerly with just 5 simultanious HttpConnections to the same server.

I tested this myself because I did not find anything regarding this in the Flex docs or on the internet.

I found that using more than 5 HTTPConnections was the reason for the Flex application to throw the runtime error.

I decided to instantiate the connections one after another as a temporally workaround: Load the next one after the other has received the data and so on.
Thats of course just temporally since one of the next steps will be to alter the responding server code in that way that it answers a request that contains the results of requests to more then one table in one respond. Of course the client application logic needs to be altered, too.

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