Click here to Skip to main content
15,888,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I did some very simple web games with AJAX (tic tac toe, connect four), for single player.

Now I want to migrate to multiplayer, so I need to establish some kind of client-server connections.

In my games I press "start game" and it shows "waiting for another player to join", but then I dont know how to approach the situation.

Can you please give me a hint? I did some client server applications in the past, but for web it's for sure different, I just need to know how to approach.

I saw some solutions used in chat's but I would like to know your opinions. I dont need to save any data in a persistent way, I just want people access my game webpage and have one of two options:
- start game if nobody is with the page open
- join game if already is someone waiting
- and so on...

From what I saw (and want) I need to create a system similar to chats where users goes to a "room" after clicking start game button (being already logged in) and waits for another user.

hummm should I create gameRoom class? How do I create rooms and assign users to it?

Thanks in advance.
Posted
Updated 23-Feb-11 6:41am
v2

1 solution

So you should check this link out; it is identical to what you need:

tic-tac-toe-multiplayer/[^]

Further Info to adapt multiplayer capability;
Building Multiplayer Capability into Your Game in One Hour[^]

I think your key to accomplish this will be using;

System.Net.Sockets class. Have a look at it:

MSDN Sockets[^]
 
Share this answer
 
Comments
Maxdd 7 23-Feb-11 12:55pm    
I appreciate your answer, but all your links go to "offline" multiplayer (not web based).

I'm studying this tutorial
http://www.junnark.com/Articles/Build-a-Web-Chat-Application-Using-ASP-Net-LINQ-and-AJAX-CS.aspx

One more time, I appreciate more suggestions.
Orcun Iyigun 23-Feb-11 13:21pm    
Accidentally added an other answer :( instead of commenting grr
Orcun Iyigun 23-Feb-11 13:25pm    
Hmm.. then you will want to use javascript making ajax calls to the server with XMLHttpRequest. This will work fine as far as you keep the communication with the server. It is s basically just web service communication.

But basically the game will be using a request model where the client continually makes requests to the server. The server does not initiate communication to the client in a web based game so what you need to do is to specify a time interval lets say N seconds and the client has to send a message to the server to get any state info. But on the other hand, using java applet and the server initiates messages to the client to give it a more real time feel so that the client wint need to make requests.

Or maybe, a different approach, not sure about it but might work as well,
Let the users to connect to a single instance of the application. Adapt your application to for each user to be uniquely identifiable by the application. You can do it by using a combination of sessions and cookies. So all of the users connected to a particular instance of the application will share the same session but each will a different cookie. But I am not sure how effiecient this is going to be.
Maxdd 7 24-Feb-11 11:27am    
I agree with you, but I still dont know how to do the following:

- When user log in, choose start game and open a new windows while see the "waiting to player" message.

- Other user sees the "room" - "join" the game - and my problem is: specifically, how do I connect one user with the other?
Maxdd 7 24-Feb-11 11:30am    
I've been here for hours studying Ajax and XMLHttpRequest, but I still dont understand how can I connect specifically two users in a room.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900