Jump to content
Sign in to follow this  
MrFish

Sockets VS Ajax?

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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I have an app using real-time access between the server and it's clients using the udp protocol thanks to nodejs and socket.ioCheck em out.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
As far as I know, only WebKit has implemented it.
Opera 11 and Firefox 4 support it, but it is currently disabled in those browsers because of security concerns. However, you can read more on the WebSocket API here: http://davidwalsh.name/websocket

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...