skip to Main Content

I am developping a restfull Web Service using WebAPI (format Json with Padding), it is about playing board based games as tic tac toe or chess or connect four…
I really want it to be asynchronious for being able to create artificial intelligence with any language easely.

The service is consumed by javascript (jquery), and the board is drawed with using canvas inside HTML5. Everything works well rigth now, Except that we have to manualy refresh to know if the opponent has played his turn, or send each other an sms, email for sending a notification.

How to make several HTML5 clients pushing notification based on a topic (here game id)?
I have heard about Web socket, is it the right direction to take?

Thank you for your help!

2

Answers


  1. Chosen as BEST ANSWER

    Short Answer : yes you can, and WebSocket IS your friend in this case.

    You first need a server that handled WebSocket Protocol, and is able to broadcast a notification for all listener listening to a subject.

    The perfect fit for you will be FastFlicker: It already come with a javascript object with clear interface easy to use. See :

    It works as follow : You connect first, then the first message you send is the subject and then all the next are broadcasted. You will receive all the messages broadcasted to your subject except your own.

    An example of application using it is MikMak itself : http://www.olivettom.com/games/

    For you, each time you choose a new game, just subscribe to subject=gameId and after a player move send a message like "1". While listening to the incoming message, if you receive "1", just do your restfull call for having the last state of the game.

    Good luck!


  2. Not a definitive answer, but you could just set an interval in javascript that makes the client check for updates from the service. If you wanted to check every 10 seconds:

    $(function() {
      timer = setInterval( function() {
          $.get(your_url, function(data) {
                  // What your client should do with the data
          });
      }), 10000);
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search