CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

Web-Based Instant Messenger with ASP.NET, Remote Scripting and WSMQ

A few weeks ago, an article appeared on O'Rielly that showed an example chat application that utilized Amazon's Simple Queue service to store chat messages.  IMO, using a middle-ware Queuing system over a Web Service is a great idea (which was the motivation for me creating www.wsmq.com), and the idea of creating a chat application to demonstrate the features of a Web Service Queue is a good one. So, I borrowed the idea, and set about to create an instant messenger using WSMQ  as the back-end chat storage mechanism.

I wanted to create a 100% Web-based chat, with out resorting to Java or other bits that don't play well in a web browser. The first problem I was faced with was how to make a request to the WSMQ server without refreshing the browser window.  I found a good remote scripting JavaScript library from Alvaro Mendez that allows you to call any method on an ASP.NET page from within client-side JavaScript.  This was the biggest hurdle for creating a usable chat application.  The rest was fairly straight forward.  It involved some relatively simple JavaScript, and some ASP.NET code to connect to WSMQ to queue and receive chat messages.  The architecture ended up looking like this.

How does it work?

  1. A controller page polls for new chat conversations, using a remote scripting (RS) call to the back-end ASPX page control. 
  2. This ASPX control connects to the WSMQ Service and peeks the users queue to check to see if there are any new conversations on the user's chat queue. 
  3. If it finds a new conversation, it returns the user name requesting the new chat to the controller via an RS callback.
  4. The controller launches a new chat window and identifies the chat conversation partner.
  5. Each chat window polls the back-end ASPX page, which connects to WSMQ,  receives the message and returns it to the calling window via a RS callback. 
  6. When the user clicks “Send“ or presses enter in the chat window, a RS call is made to send each message to chat partner's queue. 

Try it out online here, if there's no one else chatting, you can chat with yourself by clicking on your name.  You can download the full project from the WSMQ beta program page.  We're offering free accounts to use WSMQ Hosted version with our Beta program, so sign up if you haven't already. You'll be able to run the web application locally using the WSMQ Hosted queue as the chat message store

-Brendan



Comments

Darrell said:

That's pretty slick. Good job Brendan.
# January 20, 2005 1:14 AM

Dave said:

Dude, nice job!
# January 20, 2005 12:49 PM

once said:

Not to knock your solution, but I'm trying to build a chat application right now and I keep running into examples of chat applications that rely on polling the server over and over. Is there any way to build an html based chat that does not poll the server over and over to determine if there are messages available?
# March 1, 2005 8:02 AM

Brendan Tompkins said:

No, by all means, knock away. This was just intended as an example appication for my queuing systmem, WSMQ.

Well, there's no push equivalent in the web browser world, without relying on plugins, so your only real otion is polling.
# March 1, 2005 8:13 AM

Gaisa said:

..."Is there any way to build an html based chat that does not poll the server over and over to determine if there are messages available?"...

I would suggest speaking to "Chicago", the webmaster of www.magnachat.com, he created an html chat program called chatago.
The site is a working example of such and I use it myself.
# March 22, 2005 7:38 PM

Harish Nair said:

hi Brendon,

First of all, let me thank you for WSMQ. It is simply wonderful and just the thing that I was searching over the web. I wanted to build a chat application and was considering the idea of saving the messages in the database / files and writing the entire piece of code. WSMQ will save a lot of it. Thanks once again. We tested out the Beta 2 version of it. When is the first version going to be out? Heard it is open source... is it? What would we need to do to use it?

regards
harish
# November 17, 2005 1:18 AM

Harish Nair said:

hi Brendon,

First of all, let me thank you for WSMQ. It is simply wonderful and just the thing that I was searching over the web. I wanted to build a chat application and was considering the idea of saving the messages in the database / files and writing the entire piece of code. WSMQ will save a lot of it. Thanks once again. We tested out the Beta 2 version of it. When is the first version going to be out? Heard it is open source... is it? What would we need to do to use it?

regards
harish
# November 17, 2005 1:20 AM

Steve said:

http://www.wsmq.com/WSMQInstantMessenger/default.aspx

Is a dead link.  It brings you to the home page.  I don't see any chatting demo on the page even after signing up?
# April 27, 2006 2:15 PM

ali said:

ldljkfdsfds
# June 11, 2006 6:59 AM

sam said:

joe finkz dat u bloodi outragous and dat u shud actuali tell us ow 2 get on2 msn at skool! kool bredrinz !
# June 15, 2006 9:49 AM

CHIRAG said:

Really, ur idea is simply gr8, I want to develop a same kind of application , can u guide me to how to i start and how i can start work.

# October 5, 2006 12:11 AM

Ritesh Manglani said:

Great link I have found here guys. No doubt the information is useful, however, it lacks some sample code.

I am trying to develop a chat application, and would like to implement the same...ummmm...I am looking for some sample code so I can get a better understanding of things.

Hope to hear something from you guys soon.

Ritesh

# October 10, 2006 1:54 AM

amy jones said:

yea yea what ever!!!

# October 18, 2006 6:12 AM

a said:

a

# October 26, 2006 3:02 AM

jha said:

lemme check it

# December 4, 2006 9:23 AM

blih said:

hello, I tried to build your program and I got  "A project with an output type of class library cannot be started directly" and "The referenced component 'WSMQ.Data.DbProvider' could not be found" while trying to start it with a new project that has WSMQ for reference..

I'm a beginer, please help.

# January 11, 2007 5:12 PM

Linto Antony said:

Lemme check it...

# January 22, 2007 2:19 PM

Ana said:

The link to the demo is dead, basically looking t=for a way to develop an IM, has the pooling part done, cant figure out how to open the IM window on the target user browser, or even how to detect if the window has been open an is minimize, any sample code would help, Ana

# March 4, 2008 7:16 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Brendan Tompkins

Brendan has been programming with .NET since the first public beta and is owner and operator of Port Technology Services, a consultancy company providing .NET application development services to the Maritime industry. In July, 2007, he was awarded the Microsoft MVP award for ASP.NET. He's also a proud co-founder of failed .COM startup Intrinsigo, and has had a hand in the failure of numerous other businesses. He currently runs CodeBetter.Com and Devlicio.us, and lives in Norfolk, Virgina with his wife Tiara and son Ian.

View Brendan's profile on LinkedIn

Check out Devlicio.us!