1

AS3 program keeps connection open though URLLoader instance is closed using close() method. Is any way to shutdown connection immediately once data is loaded?

Checking connection status from commandline using netstat command, it is showing as Eshtablished.

Please suggest.

parth
  • 61
  • 1
  • 1
  • 8

1 Answers1

1

URLLoader is a HTTP wrapper. You have to use HTTP stuff to get it done. In order to close the connection you would have to send the Connection: close HTTP header along with the webserver response. (Note that the default for most webservers is Connection: Keep-Alive, and it is the behaviour you are seeing).

In order to send it from Flash to the server, you would have to have the local-trusted or AIR application sandbox. This is not possible when running in a browser (on the internet).

From the docs:

In Flash Player and in Adobe AIR content outside of the application security sandbox, the following request headers cannot be used, and the restricted terms are not case-sensitive (for example, Get, get, and GET are all not allowed). Also, hyphenated terms apply if an underscore character is used (for example, both Content-Length and Content_Length are not allowed):

Accept-Charset, Accept-Encoding, Accept-Ranges, Age, Allow, Allowed, Authorization, Charge-To, Connect, Connection, Content-Length, Content-Location, Content-Range, Cookie, Date, Delete, ETag, Expect, Get, Head, Host, If-Modified-Since, Keep-Alive, Last-Modified, Location, Max-Forwards, Options, Origin, Post, Proxy-Authenticate, Proxy-Authorization, Proxy-Connection, Public, Put, Range, Referer, Request-Range, Retry-After, Server, TE, Trace, Trailer, Transfer-Encoding, Upgrade, URI, User-Agent, Vary, Via, Warning, WWW-Authenticate, x-flash-version.

oxygen
  • 5,891
  • 6
  • 37
  • 69
  • Thank you, this is really helpful! I can understand from here is I need to set response header "Connection: close" from webserver. If this is correct, I cannot use this approach, as I am dealing with the client side code only. Any suggestions from client side would be great! – parth Oct 05 '12 at 18:29
  • I have included the client side perspective also. This is a complete answer, you won't get better than this. Since you can't even set a header on the server side (not even mod_headers, webserver config, etc.), I won't even get you into elevating permissions so you can connect directly to the socket and implement your own HTTP parser (as it requires a lot more than configuring a webserver). – oxygen Oct 05 '12 at 18:53
  • Have you tried destroying the URLLoader object (this might not work, the connection is maintained by Flash to be shared by any URLLoader objects), and giving a hint for garbage collector to Flash? http://stackoverflow.com/a/11450161/584490 – oxygen Oct 06 '12 at 08:00
  • Yes, after close() method call, I tried to nullify the loader object, but not working. Is there a specific way to give hint for garbage collection to flash? Also you are correct, connection is maintained by Flash, as I observed that when editor is closed only then it disconnects. Thank you! – parth Oct 06 '12 at 09:51
  • See the link to an answer in my previous comment. – oxygen Oct 06 '12 at 10:22
  • Thank you for a very specific response. It is working with garbage collection. – parth Oct 07 '12 at 13:43