Reputation: 14464
I got an AJAX online game that calls server few times per second. AJAX calls are good, but still they are slower than normal TCP/IP-sockets connections.
So my questions is, can I improve my game by using - if flash is available - some flash application for server connections? Or maybe there is some solution with Firefox addon (70% of my users uses Firefox) ?
Upvotes: 1
Views: 267
Reputation: 8701
Just happened to come across this new JS library that might be helpful for you (announced today by ajaxian):
From their site:
Kamaloka-js is an implementation of the AMQP messaging protocol in native JavaScript. It is setup to be used with Orbited but can be used with any library which produce TCPSockets in the browser similar to Orbited.
Another similar solution (using flash): amqp-js
Upvotes: 2
Reputation: 1549
If you do this, please make sure you do something sensible when the user has a proxy configured, even if it's just a message telling the user that proxies aren't supported.
Proxies are so easy to forget.
Upvotes: 0
Reputation: 13112
Similar to what James Black said, don't jump straight ahead and rip replace everything to Flash, before you figure out where the bottleneck is (if one exists).
I think you might also be missing some parts of the picture, judging from some of the comments...
I want to lay out all the layers in your communications, just to make things clear - point is, its unlikely ALL of it is the problem, and youd be better looking at the problematic layer only.
So, to sum up - switching your client to Flash might have 2 possible benefits: the client itself may run faster (depending on your client), and it allows you to call sockets directly bypassing 3 above (http). Again, note that the 2nd benefit is dubious at best - benefit is questionable, and there are clear downsides to it.
Unless the bottleneck is the client display code, you're better off either switching to JSON (or other data format), or optimizing your server code. Once you profile and figure out where the problem is, you'll better know where to focus your efforts. I find it highly unlikely that Flash will help with that. (again, since it IS a game, you may need the improved display).
Upvotes: 0
Reputation: 41858
Before doing this optimization you may want to first profile, to ensure that the slow part is the socket connection between javascript and the server.
I tend to profile the server-side, and then I profile from javascript to the server and back, and the difference is due to the socket connection.
Once you have some numbers, then any other change you make, such as what Makram suggested, can be profiled, to see if there is sufficient improvement.
If your calls to the server are some sort of polling you can look at using Comet to help with that: http://en.wikipedia.org/wiki/Comet_%28programming%29
Upvotes: 2
Reputation: 8701
XMLSocket
objectsflash.external.ExternalInterface.call
from Flash to call JS functionsFlash/JS communication via ExternalInterface
is very fast, which can handle the speed provided by sockets replies.
I hope this helps.
Upvotes: 3