C# port of dChat · Curiosity is bliss

Curiosity is bliss    Archive    Feed    About    Search

Julien Couvreur's programming blog and more

C# port of dChat

 

I ported dChat, an IRC-like web chat , to C#. Try the online demo of the original dChat.

My goal was to make it really easy to use on windows/IIS in a windows domain. So, no compilation is needed, as you can run it by just deploying the source files to an IIS webserver and configuring the "Directory Security" to only use "Integrated Windows authentication".
You can then load the url for chat.aspx in a browser and start using it.

A useful configuration is to add chat.aspx to the "Default Document" list, so that if you load the url for the directory instead, it'll default to dnChat.

One of the differences with the dChat is that there is no DB or persistent storage (at least yet).
Another difference is the use of windows authentication.

Get the zipped source files for dnChat.

The files:

  • chat.aspx: is a mostly static html file that has includes javascript remoting tricks to communicate to f.ashx.
  • f.ashx: a C# HTTPHandler that handles the remote function calls from the browser.
  • online.js: some utility javascript functions. Some of the javascript from chat.aspx could be moved in there too...

Note: The .Net framework needs to be installed on the machine in order to run C#. No need for the SDK, the redistributable is enough. Also IIS needs to be configured to use it (which should automatically get setup when installing .Net), but in case it is not, you can run "aspnet_regiis -i" to fix it.

The poll rate is currently set to 3 seconds, but it should be easy to make it adaptative: the server could set it to 10 or 15 seconds if you haven't received a message for a long time, but when the channel is active it could go back down to 3 seconds.

Update: Since a couple of people showed interest in extending dnChat, I started a dnChat Sourceforge project with Weston Weems.
Also, Mesalem posted a variation on dnChat at the Code Project, check out "Simple Chat Application in ASP.NET".

Update: ASP.Net 2.0 comes with a remote scripting feature: client callbacks (via).


Update (2005/05/11): Fixed an issue with unicode characters not being transmitted properly. Now using encodeURIComponent instead of escape for unicode characters on the querystring. Updated the zip file above and on Sourceforge.
Thanks to Vitor Cardoso for pointing the issue out and troubleshooting with me.

______________________________________

I am trying to use your app but i dont want to have an account for every
user. Is there a way to allow anonymous with different usernames? Or a
better way to explain to the users other then trial and error with
optional user names. (If 2 users login with the same name one gets
kicked)


Thanks,
Brian

Posted by: Brian Yelm (September 1, 2004 03:14 PM) ______________________________________

Brian,
I had deleted your comment by mistake, so I re-posted it and replied by email.
When I ported dChat to C# I changed the authentication model to use network authentication as part of a windows domain. This solves the issue of unique usernames, because the domain controller ensures there is no collision.

I wouldn't be too difficult to switch back to the dChat model, where you just pick your own username. But then, like you pointed out, you need to handle the duplicate username case. I would probably list the usernames of the people currently using the system, on the "login" page, so that you can tell which ones are already taken...

Posted by: Julien Couvreur (September 1, 2004 03:22 PM) ______________________________________

Hi Julien,

Could you explain how to use this using Forms authentication instead of Windows authentication. I have my own accounting system so could fill the query string with a username, BUT, based on Forms auth.

The chat app looks clean and efficient, opposed to other I saw.

Thanks,

Danny

Posted by: Danny (September 11, 2004 08:03 AM) ______________________________________


Plz .i want to Know ow to Browse The Directory From C# windows Button Command .


Posted by: Dharmendra Gour (October 4, 2004 07:47 AM) ______________________________________

Oh rad!

Posted by: Glen Murphy (October 6, 2004 09:22 PM) ______________________________________

well i tried installing net.framwork yet i still cannot get this application to work. i 've read your docs posted on this page perhaps im missing something. ps im new to this

i've aslot tried executing the file C:\dnChat\chat.aspx as a url and it didn't work, intead i get text in the aspx that pops up in notepad.

im running windows xp pro with net framework installed, php and perl

Posted by: ada (November 20, 2004 07:29 PM) ______________________________________

Hi Ada,

Could you check that you have the IIS webserver installed? To do this, go in the Start menu, select Run... and type "inetmgr". If you get an error, it means you didn't install IIS as part of your windows components.

If you have it installed, do you know where your document root is? A simple test is to put a file (say "test.txt" with a "hello" string in it) in that directory and try and load it in a browser (http://yourmachine/test.txt ). If you are able to get the "hello" in the browser than you are good to go and deploy the dnChat files into that directory.

Let me know how it goes.

Posted by: Julien (November 23, 2004 11:21 AM) ______________________________________

commnet the code on asp.net C#.

problem:

any user can use querystring
http://localhost/chat.aspx?user=user1
so sameone might type it and they might having
same nick.

Posted by: teoh (February 12, 2005 07:57 AM) ______________________________________

Teoh, you're right. But that code (looking at the "user" querystring parameter) is mostly for debugging, so that a single user can repro a multi-user scenario.

Posted by: Julien Couvreur (February 17, 2005 10:22 AM) ______________________________________

Hi Julien

This is a very nice and handy piece of code.
I want to report that it’s not working with accented characters like French or Portuguese.
Can you post a version working for these (often) forgotten languages ;) ?

Best regards

Posted by: vcard (May 9, 2005 10:27 AM) ______________________________________

Re: accented characters
I just tried some accented characters like "ĔĕėĘĘœצקҜấạẃчÈÉÃ" but it was working fine. I tried both Firefox and IE for the browsers.
Can you give me some more details on your repro? We can follow up on email.

Posted by: Julien (May 9, 2005 10:38 AM) ______________________________________

Can we do personal chat?

Posted by: vishal (August 31, 2005 05:28 AM) ______________________________________

i need to know if there's a way to refresh the chat room faster without refreshing the whole page?

Posted by: joseph (April 24, 2006 03:51 AM) ______________________________________

Vishal,
There is no support for channels and private conversations. I'm sure that now that some of the javascript techniques have become popular (AJAX trend), you should be able to find more powerful chat applications based on the same model.

Joseph,
You can change the polling frequency for getting new messages, there should be no need to refresh the whole page.
Using a different technique to get messages from the server (push), it should be possible to get the new messages instantly, without waiting for the next poll. Search for for "ajax comet" for more info.

Posted by: Julien Couvreur (April 24, 2006 04:03 PM) ______________________________________

Hi Julien

Is there a version to use in Sharepoint (wss)?

Thanks.

V.Cardoso

Posted by: v.cardoso (June 28, 2006 09:12 AM)
comments powered by Disqus