Jump to content

Sockets VS Ajax?


MrFish
 Share

Recommended Posts

I'm making a multiplayer game with the HTML5 canvas. Since it is multiplayer the client needs to have a way of communicating actions to the server and also constantly getting information from the server. I have been, for testing purposes originally, been using ajax to send and receive data. I'm wondering if this is an acceptable way to send and receive information for a multiplayer game. It seems to work fine sending information because the information goes through very quickly and the logs show there really is no noticable time difference between a request sent by the client and recieved by the server. But I then tried to setup a script that polled the server for game information about 30 times per second with ajax and the site kind of went down for a bit after about 10 seconds of the script running. The funny thing is I cannot view any page for hours with the computer after I use the script but I can use a proxy and see my site is still running. It just doesn't want to give me information I'm guessing. So I have to believe it's just a server setting to stop giving me information if I make too many requests per hour.So is this an acceptable way to do this or should I be using sockets? The reason I didn't turn to sockets right away is because my server doesn't support real-time running software. Only one-time-run page requests.

Edited by MrFish
Link to comment
Share on other sites

That's far too much. AJAX can't be used for real-time connections because it uses the HTTP protocol. The HTTP protocol opens a request, sends and receives information and then closes it. Aside from that, the requests are asynchronous, so you don't know what order the request responses will be received. Finally, the browser limits the amount of requests that can be open at once.AJAX is OK for turn based games, like chess, where you make a request every 5 seconds or so.Javascript doesn't have a way to manage sockets. Usually people let Javascript communicate with a hidden Flash movie or a Java applet to work with sockets.

Link to comment
Share on other sites

Javascript doesn't have a way to manage sockets. Usually people let Javascript communicate with a hidden Flash movie or a Java applet to work with sockets.
I thought HTML5 supported web sockets. I was looking at a tutorial and it appeared they were using JS to send and receive sockets.
Link to comment
Share on other sites

You are correct about the new API. As far as I know, only WebKit has implemented it.EDIT. And the tutorial I looked at requires command-line executive privileges to execute the server side. You might not have that if you are leasing space from a commercial host.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Exactly, which is why I've opted to use ajax instead. If only webkit browsers support it, it's probably not worth getting into just yet anyway. I'll just put this one on hold or switch to Java.

Link to comment
Share on other sites

Web Sockets is not technically part of HTML 5, according to what I've read (http://dev.opera.com/articles/view/introducing-web-sockets/). According to that article, it looks like when the next generation of browsers will be able to handle web sockets, except for IE. As far as I saw, it did not mention IE at all.Anyway, web sockets will be a very, very good way to go, and hopefully they will be available soon. If you're building a game, you might consider web sockets, as developing a stable game will take quite a bit of time, and web sockets may be available to most people using modern browsers when your game gets to a stable stand point.It will really depend on your development time-line and such on what method you should use.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...