5Mixer / mphx

A little library to let you make multiplayer games easily with Haxe. No longer maintained and better options are available.
MIT License
125 stars 15 forks source link

[fix] flash server #32

Closed yannsucc closed 8 years ago

yannsucc commented 8 years ago

some fix for this issue : https://github.com/5Mixer/mphx/issues/19

5Mixer commented 8 years ago

Thanks @yannsucc. I, unfortunately, have no flash experience, so your experience is valuable. I'm not sure about using timers to solve issues however - it seems like a very 'hackish' solution that could be prone to one off errors/crashes, such as if the network is slow and messages are delayed beyond the timer length. As I said, I don't understand flash enough to know about these policy files, so I can't currently propose a better solution. With that, I'm going to pull this in.

Perhaps unit tests would be a good idea for this library. I'll write an issue up for that now.

yannsucc commented 8 years ago

Yep, this solution is not ideal, but working. I don"t know how to improve this. (maybe close the flash socket on port 843 server side, one frame later instead of sleep(), and client side, wait few frames before sending message...)

The problem went on a distant client connected to a distant server.

When the client call flash.socket.connect(), two socket is opened to the server. (on port 843 (adobe air specifications, and the specified port (call it 8000 for exemple))

When the server accept the connection on 843, it write the crossdomain.xml (to authorize the as3 client code to communicate on network on a specified domain and port ) and instant close the socket.

Here, calling socket.flush(); socket.close(); add problems. flush() don't have time to correctly write data on socket (it seems). so i added a sleep.

On the same frame (server side), the server accept the connection on port 8000. And, on client-side, the flash event "Event.connected" was called. And mphx directly send "waiting message list" before the connection.

But sometimes, the crossdomain.xml is not receive at time. It must be receive BEFORE any message send on port 8000. So in random case, the crossdomain is received after mphx send the "waiting message list" And Flash send a Flash Error event about Security domain, and instant close the connection.

There were no Flash event about receiving the crossDomain... So we can't add a callback for this. The only i found now, is added a delay to be sure that the client receive the crossdomain.xml

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html

Adobe Flash Security is a pain...

(Sorry for my painfull and bad english)