ActionScript 3.0 sockets can’t reconnect,
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.)
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.
I must be missing something very simple.
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.)
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?
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.
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