Jump to Navigation

Preventing multiple instances of Flash Movies

Currently, Flash does not natively support prevention of multiple instances, so a workaround is needed. Why would anyone want to prevent multiple instances anyway? Well, I use Flash as a Chat client, so allowing a user to run multiple instances would mean that they could join the chat multiple times, which is not really a wanted feature. So how do I prevent users from joining the chat multiple times?

As there is no way to do this on the client side, a server side solution is needed. So my first thought was to only allow each user with his account to join once, which should work fine in most cases. There is only one problem: When a user’s connection drops, the server wouldn’t know that and would block him from rejoining the server until the old client timed out. This is quite user unfriendly, so a different solution is needed. A different approach would be IP-based blocking (1 connection per IP), where this problem wouldn’t occur, but that would cause people behind routers not to be able to chat at the same time. Again unacceptable for me, so I thought of a third way:

Whenever a client connects to the server, the server will look through all existing users and check if there is one that has the same account. If no, it allows the client to continue normally. If yes, it will send a “alive” message to the other client and first let the new client continue as usual. At the same time, it will wait for an answer from the other client. If a message is received, the new client will get disconnected, as the user is already connected.

This approach works very well on my server. To make this system work for guests too, a unique key would be needed for each user, which should get saved as a flash cookie (browser wide). That will also prevent the user trying to join by opening the chat in different browsers.

Comments are closed.