Is there any advantages to developing one with WebSockets rather than AJAX? I went through google and haven’t found a single example on how to make AJAX calls to a C# server.
Also how would I create session server side for players and be able to know which ajax call is from which player?
Your question is made up of several ones so I’ll answer them one by one
1. Is there any advantages to developing one with WebSockets rather than AJAX?
Yes, but you need to strongly consider your use case. WebSocket should be used if the webpage needs to pass a lot of messages to the server and vice versa. AJAX should be used for retrieval of data. As mentioned by Kolink, that means AJAX is suited well for turn-based games and WebSocket’s advantage is with dealing with real-time communication.
There is also a middle ground called Comet. This technique uses AJAX to accomplish something close to WebSockets, but it represents an abuse of HTTP protocol and is one of the reasons WebSocket was created.
The three diagrams below should further illustrate the differences. They are a representation of how these technologies are used if you need to create a bi-directional communication channel between the webpage visitor and your server:
AJAX:
Comet:
WebSocket:
2. I went through google and haven’t found a single example on how to make AJAX calls to a C# server.
Try either of these two:Ooops, you asked about AJAX. I am not very familiar with C#, but the best way would probably be to have an ASP.NET script to which you make an AJAX call. There is nothing special that has to be done on the server side to support AJAX.
3. Also how would I create session server side for players and be able to know which ajax call is from which player?
This can be accomplished by authenticating each AJAX call with a client ID. Sometimes they’re also called tokens. If you use an existing implementation it is probably going to have a mechanism to do that.