-2

I am working on a tic-tac-toe game which two gamers can play simultaneously, after every click I have to update the database but my problem is that how the other gamer will know that next player has clicked a box and updated the database without page refresh because that will take a long time?

Arun Killu
  • 13,581
  • 5
  • 34
  • 61

1 Answers1

2

There are a few options.

1) Use AJAX polling every so often. A simple example taken from this link and modified:

function doPoll(){
    $.post('endpoint(url or page)', function(data) {
        // process results here
        setTimeout(doPoll,5000);
    });
}

2) Look at web sockets. This post has a good overview: In what situations would AJAX long/short polling be preferred over HTML5 WebSockets?

3) Take a look at SignalR; from the website:

ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization.

This was also a nice overview of several options.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257