ActionScript 3.0 sockets can’t reconnect

Question :

ActionScript 3.0 sockets can’t reconnect,

Answer :

I’m having trouble connecting (via the Socket and XMLSocket classes) to a TCP listener after a connect timeout.

I have a flash applet that needs to maintain a TCP connection to a server. I have implemented timeouts using Timers, a ping-pong system, etc. However, there’s a problem. Upon calling Socket.connect(), the flash player (9.0.115 and many other stables before that) sends 3 connection requests by way of SYN packets, with some time in between. If none of those are replied to (e.g. because the server is down), I cannot get the applet to [attempt to] connect to the server. Ever. That is, within the lifetime of the applet.

To clarify and/or summarize:

For any host/port pair given to Socket.connect() or XMLSocket.connect(), if the call fails, any subsequent connect() calls to any other Socket (or XMLSocket) instances within the lifetime of the Flash applet to the same host/port pair get ignored. (At least as far as I can tell using a packet sniffer.)

Read More  How to get started writing a code coverage tool?

I have tried calling numerous Socket methods, destroying¹ and recreating the objects, using a pool of Sockets, and various other methods I can’t remember right now; all to no avail.

My current solution is to notify the parent webpage through a JavaScript call and let it reload my applet. It’s not a pretty solution, and I’m not about to implement workarounds for the problems it causes, just because Flash can’t handle socket connections properly.

I must be missing something very simple.

Any ideas?

1: I know you can’t really destroy objects; I just remove all references to them and hope for the best. I haven’t tried to explicitly invoke the GC in this case. (Though I think I did try putting the Socket inside an Array and using delete.)


Yes, it works as expected if the connection is successful (even if the connection drops later on.)

Read More  How can I convert IEnumerable to List in C#? June 10, 2022 by Eiji I am using LINQ to query a generic dictionary and then use the result as the datasource for my ListView (WebForms). Simplified code: Dictionary dict = GetAllRecords(); myListView.DataSource = dict.Values.Where(rec => rec.Name == "foo"); myListView.DataBind(); I thought that would work but in fact it throws a System.InvalidOperationException : ListView with id ‘myListView’ must have a data source that either implements ICollection or can perform data source paging if AllowPaging is true. In order to get it working I have had to resort to the following: Dictionary dict = GetAllRecords(); List searchResults = new List(); var matches = dict.Values.Where(rec => rec.Name == "foo"); foreach (Record rec in matches) searchResults.Add(rec); myListView.DataSource = searchResults; myListView.DataBind(); Is there a small gotcha in the first example to make it work? (Wasn’t sure what to use as the question title for this one, feel free to edit to something more appropriate) Try this: var matches = dict.Values.Where(rec => rec.Name == "foo").ToList(); Be aware that that will essentially be creating a new list from the original Values collection, and so any changes to your dictionary won’t automatically be reflected in your bound control. Categories question Post navigation .NET unit testing packages Authenticating Domain Users with System.DirectoryServices

The only event to trigger this is the case when the server doesn’t respond at all; it’s as if Flash marks the host/port combination as “offline” and doesn’t bother sending any more packets to it for the lifetime of the applet.

I suspect an active refusal of the connection (e.g. host is online but not listening to the port) doesn’t cause this.

I get no error message or feedback of any other kind from the Socket.

Have you ever called connect() more than once to the same host/port pair, when the first one failed?
How did you know the first connect() failed? And before subsequent connect() calls, did you do anything to reset the socket?

Read More  Checking FTP status codes with a PHP script

,

This could be related to the unresolved bug which in turn may have the same root cause as

This build should be fixed in the
current public beta release found on

Edwin Wong – [09/23/08 04:49 PM ]

I’d recommend you give the  a shot…

That’s the answer ActionScript 3.0 sockets can’t reconnect, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you