The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Design problem (web-based chat)

Hey all,

As a hobby project I'm trying to implement a Web-based chat application in ASP.NET 2.0 to learn Ajax+server=side programming. I'm very new when it comes to web-based application so I'm in process of figuring out the right design. I've read existing articles(on CodeProject & elsewhere) on how people implemented a chat application using ASP.NET and they helped but I'm still left with few questions and I will really appreciate if someone can answer me.
So here is my proposed design,

1)- All incoming messages will be stored in a database table named "Chat" and it will have the following fields
a) ChatID (Auto-increment by 1)
b) ChatMessage (nvarchar)
c) SenderName (nvarchar(

So when a message comes from a client (i.e. browser) it will be stored in above table. ChatID will be incremented by 1. Text will go into ChatMessage field & SenderName will have the name of the Sender. So far so good.

2) OK, I've already figured out a way to send message from the client side and I'm now able to save the messages in above DB table.

3) Problem is that, I cannot figure a way as to how will clients receive the message. I mean at any point DB table above may look like this

0 | hi there | michael
1 | I'm good how're you? | Steve
2 | Hi all, sorry I'm late | John
3 | No problem , glad you made it :) | michael

I cannot figure out a way as to how michael will receive all messages other than his own. Likewise how, John will receive all messages other than his own? AS far as I understand, I know that client has to poll the server (using setInterval()) to receive new messages but I'm not sure about the HOW part?

Any ideas, guys? Any help will be highly appreciated.

Aneel Send private email
Thursday, July 17, 2008
Pretend that instead of writing a web application, you are doing something similar with people.  The chatters write their messages on index cards and hand them to someone acting as a chat coordinator.  Periodically, the chatters also ask the chat coordinator for any recent messages, and the coordinator copies the messages and gives them to the chatter.  Get some friends and try it out to see what works.
Franklin Send private email
Thursday, July 17, 2008
Should point out, you have a multi cast chat there.
No way to distinguish sessions, verify right to view, etc.

But as you said, it is a test.
Roger Willcocks Send private email
Thursday, July 17, 2008
Do All users receive a message when sent, i.e. a Chat Room?  If not you might need to store a recipient on the table.

As far as how to get the messages how about this?
When you return messages to the client also return the highest message ID at that point.  When the client polls, have them send the message ID back to you.  Then your code might look something like this:

int highestChatID = "select max(ChatID) from messages"

SELECT * from messages
where ChatID BETWEEN LastChatIDFromClient AND highestChatID

return highestChatID
Friday, July 18, 2008
Thank you, everyone.

Ted, what you proposed made a lot of sense. One last question, my ID field will be auto-incremented. Do auto-incremented fields have some kind of bottleneck in the longer run? OR I should just not worry about it. Any ideas, folks?

Thanks again for all of your help. Really appreciate that.
Aneel Send private email
Friday, July 18, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz