What is the best Design/Way to keep user connected?
Asked Answered
P

3

9

Am working on a POC for self learning in which I want to keep my user connected in LIVE pattern. For example, A game in which 4 user can play at a time , here I need to keep this user connected to my game .

M not good at Socket type of programming and love to do that in Services way.What i wana know is 'What is the best way of doing this'. According to my initial Brain Storming, I have decided that I will use SilverLight(In Browser Or Out of Browser) as Front end [I have no issue in that].

I m more concern in back end. Either I make an handler or make a WCF service or use full duplex service and use pooling mechanism for that. As a random thought I come up with a Timer type logic that will fire every after 10 seconds at clients end and get status like

  • Is it now Its turn to roll a dice

  • Home many user left (in case if some of them left)

  • What are connected user status in game like there score/points ect and update
    game view according to this at his end

Kindly place your best answers here that will help me to learn this.

Regards and thanks in Advance

EDIT:

Starting Bounty as i need more feedback.

FH

Pigeon answered 7/12, 2010 at 6:1 Comment(0)
M
11

Fasih,

Since HTTP is stateless, you cannot make 2 way communication from your code. But there is a workaround if you are using AJAX. As you said timer is a one way. Another one is called COMET or Reverse AJAX.

This simulates the two way communication without relying on timer. To accomplish this you have to make a long running AJAX calls to the server, and the call is only returned if there is a change to update. Assume simple web chat scenario. 2 users make a long AJAX calls to the server, and both are polling the common medium (say DB), if the user1 sends some text, it will get updated and the user 2's waiting AJAX call pick up the text and return. And again both users will make a long running call to listen each other.

As you already decided to go ahead with silverlight, you can use WCF duplex channel to emulate the 2 way communication. As i explained earlier, dont go with timer logic. Its not instant if you are polling the server for 10 sec (anything can happen in a game within 10 sec), and it will increase the server load if you poll for each second.

So avoid timer logic and use long running AJAX calls.

If you are looking for options other than WCF duplex channels, HTML5 web sockets and COMETs are other ways to go.

check out this post for browsers supporting web socokets.

Micromho answered 7/12, 2010 at 6:36 Comment(6)
nice reply. i like that. From this i can make my own Loon running Ajax calling mechanism. Let me check it out . will updatePigeon
Just read your answer now..better than mine..right that server load will be more if timer is used..Hortatory
Buddy, I said I just read your answer now..if I had read it I wouldn't have bothered to comment what I did and said ur answer is better than mine....just for the sake of courtesy..Hortatory
No probs.. happens all the time with me :DHortatory
Do you know how long running ajax calls work on the server or any good article on this?Hortatory
@Mahesh, This is same as normal ajax calls. Only difference is normal AJAX calls returns immediately by completing its dedicated work. Long running calls lives in server and subscribed to some other event to notify. Will only return to caller if it receives the data from publisher. Assume in a web chat scenario, all long running calls polls database(subscribe) or some other data store to look for data from other users. And will return to caller if there is anything to update. Think of it is a infinite while loop waiting for the condition to satisfy to exit the loop.Micromho
H
1

Basically it is a question of being able to push data to the client from the server. So I was thinking is a subscriber publisher architecture, you can create a queue(in a db table for ex) on the server for each of users that are connected, and have an ajax calling a web service that will pull data from the table.

Every message should be encapuslated as a command for the client. So you can use different messages for each operation that the client is capable of. {command:display,text:"user blah blah has logged in"} another command could look like {command:rolldice, text:"roll the dice"}

Let me know what you think...

Hortatory answered 3/1, 2011 at 9:29 Comment(0)
R
1

If you've decided to go for WCF then I would suggest you to use callbacks.

More info here: WCF: Working with One-Way Calls, Callbacks, And Events

-- Pavel

Raillery answered 4/1, 2011 at 7:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.