ActionScript 3.0 套接字无法重新连接
连接超时后,我无法(通过 Socket 和 XMLSocket 类)连接到 TCP 侦听器。
我有一个 flash 小程序,需要维护与服务器的 TCP 连接。 我已经使用计时器、乒乓系统等实现了超时。但是,有一个问题。 调用 Socket.connect() 后,Flash 播放器(9.0.115 以及之前的许多其他版本)通过 SYN 数据包发送 3 个连接请求,中间间隔一段时间。 如果这些都没有得到回复(例如,因为服务器已关闭),我将无法让小程序[尝试]连接到服务器。 曾经。 也就是说,在小程序的生命周期内。
澄清和/或总结:
对于给 Socket.connect() 或 XMLSocket.connect() 的任何主机/端口对,如果调用失败,则对任何其他 Socket(或 XMLSocket)实例的任何后续 connect() 调用在 Flash 小程序的生命周期内,同一主机/端口对将被忽略。 (至少据我使用数据包嗅探器所知。)
我尝试过调用许多 Socket 方法,销毁并重新创建对象,使用套接字池以及我现在不记得的各种其他方法; 一切都无济于事。
我当前的解决方案是通过 JavaScript 调用通知父网页并让它重新加载我的小程序。 这不是一个完美的解决方案,而且我也不打算针对它引起的问题实施变通办法,只是因为 Flash 无法正确处理套接字连接。
我一定错过了一些非常简单的东西。
有任何想法吗?
1:我知道你不能真正摧毁物体; 我只是删除所有对它们的引用并希望一切顺利。 在这种情况下,我没有尝试显式调用 GC。 (虽然我认为我确实尝试将套接字放入数组并使用删除。)
是的,如果连接成功,它会按预期工作(即使连接稍后断开。)
唯一的事件当服务器根本没有响应时触发这种情况; 这就好像 Flash 将主机/端口组合标记为“离线”,并且在小程序的生命周期内不再向其发送任何数据包。
我怀疑主动拒绝连接(例如主机在线但不监听端口)不会导致此问题。
我没有从套接字收到任何错误消息或任何其他类型的反馈。
当第一个失败时,您是否曾经多次对同一主机/端口对调用 connect() ? 你怎么知道第一个 connect() 失败了? 在后续的 connect() 调用之前,您是否执行了任何重置套接字的操作?
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.
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.)
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能与未解决的错误 FP-269 有关,而该错误又可能与与 FP-67 的根本原因相同。
我推荐您尝试一下最新公开测试版...
This could be related to the unresolved bug FP-269 which in turn may have the same root cause as FP-67.
I'd recommend you give the latest public beta a shot...