6 Replies - 614 Views - Last Post: 24 February 2013 - 01:38 AM

#1 jskidd3  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 16-September 12

JavaScript and Web Sockets

Posted 23 February 2013 - 06:33 AM

Hey,

So I've recently created a classic Battleships game using 2D arrays in Javascript etc. Now, what I'd like to do is open the game to allow players to player together online.

The way I'd like to go about doing this is using web socket. I've had a look around and can't seem to find any beginners guides to Web Sockets or anything, are they hard to use? I've worked with a client-server relationship before in Java, but doing it over Javascript through Web Sockets is completely new to me.

If anyone could give me an overview as to what sort of set up I should do and how I should go about finding the game to do so, I'd really appreciate it.

Thanks!

This post has been edited by jskidd3: 23 February 2013 - 06:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: JavaScript and Web Sockets

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,499
  • Joined: 12-December 12

Re: JavaScript and Web Sockets

Posted 23 February 2013 - 08:09 AM

What's wrong with this page? First listed from a Google search.. :whistling:
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,499
  • Joined: 12-December 12

Re: JavaScript and Web Sockets

Posted 23 February 2013 - 08:15 AM

You should be aware of the support for this feature as well.
Was This Post Helpful? 0
  • +
  • -

#4 jskidd3  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 16-September 12

Re: JavaScript and Web Sockets

Posted 23 February 2013 - 08:19 AM

Jesus Christ that's embarrassing, I swear down, I looked so hard and didn't even see that.

To open up the question a little bit more, what do you think is the best way to go about storing information about a player in a game like this http://browserquest.mozilla.org/ ?

BrowserQuest itself uses LocalStorage because they wanted to show it off, but I need something more long term. I suppose the first thing I think of would be to just make calls to a MySQL database and insert the data like that, but is that safe considering Javascript is a client side language?

Thanks
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,499
  • Joined: 12-December 12

Re: JavaScript and Web Sockets

Posted 23 February 2013 - 08:35 AM

Javascript wouldn't be accessing the MySql database, you would need a server-side script for that.

With Ajax, Javascript makes the request, a PHP (or other server-side language) processes the request and may return some data that the JS can use in the page.
Was This Post Helpful? 0
  • +
  • -

#6 jskidd3  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 16-September 12

Re: JavaScript and Web Sockets

Posted 23 February 2013 - 09:15 AM

Ok thanks Andrew. I'll be running the server Node.js. Looks like I've got a lot of learning to do :P
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: JavaScript and Web Sockets

Posted 24 February 2013 - 01:38 AM

but shouldn’t WebSockets & node.js automatically point to socket.io in a google search?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1