Jump to content

Long Polling vs WebSockets


steveo16
 Share

Recommended Posts

Hey there.  I was just curious how many people were using long polling or WebSockets for their online games.  I'm working on a turn-based game that feels a bit like a board game in the browser, and for the early prototype I've opted to use long polling because it was easier to setup.  At some point I'd like to make the switch to WebSockets, but if enough people seem to be having success with long polling then I'll probably de-prioritize the effort.  Currently my game uses a 7 second refresh interval so there's a _bit_ of lag, but most of the time it isn't too noticeable.  I was hoping to hear other people's thoughts on the matter.  Thanks!

Link to comment
Share on other sites

Get yourself on the sockets bandwagon, support is now superb and there are a few wrapper libraries you can use to smooth out any edges. Once you've learnt it (it literally takes 2 minutes, its just an event emitter) its far easier to set up than long polling and most libraries will fall back to long polling if they can't establish a socket connection.

There are plenty of guys and gals working on real-time connected games here, this is one.

Link to comment
Share on other sites

Darn, I was really hoping to move an item to the backlog but it sounds like WebSockets should be a priority.  I have some old socket code from a chat app I can dust off.  I'm kind of kicking myself for not using that code in the first place.  Thanks for your feedback!

Link to comment
Share on other sites

  • 3 weeks later...

I guess this would give me a good opportunity to learn NodeJS.  My old socket server code is written in PHP and is probably pretty dated by now.

Do you happen to have any experience with wss, or secure WebSockets?  What's the best way to make sure the WebSocket connection is encrypted and secure?

Link to comment
Share on other sites

I am using WebSockets for my game and only use traditional HTTP Requests in response to an action when needed - like loading player info. I have always hated long polling so when I could, the first thing I did was use websockets, I didn't regret it. There are also a lot of libraries out there too. They even fallback to long polling if needed (at least some of the ones I have looked at).

Link to comment
Share on other sites

13 hours ago, steveo16 said:

I guess this would give me a good opportunity to learn NodeJS.  My old socket server code is written in PHP and is probably pretty dated by now.

Do you happen to have any experience with wss, or secure WebSockets?  What's the best way to make sure the WebSocket connection is encrypted and secure?

I've never encrypted websockets, although they're just http so the same principles apply using tls/ssl. 

Encryption is almost always a good option but a lot of the time your ws connections aren't carrying much information, or should not be, so there is a counter argument that man-in-the-middle attacks are fairly useless for anything other than disrupting your game as no sensitive info is ever in the pipe. Having said that it should be dead easy to set up now and cheap too. Maybe look at Let's Encrypt for your certs.

Link to comment
Share on other sites

I setup some basic socket server encryption in the past using stunnel.  It seemed kind of hacky so I was wondering if there's a better way to go about it.  I'm a big fan of encrypting all the things, so if I do end up switching from long polling to websockets I'll definitely want some kind of encryption in place.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...