开发者

C# Instant messaging

I'm working on a instant messaging program in C#(for learning only).

Just wanna to know if my way is right or wrong.

I created a Client class whice contains a Netwo开发者_JAVA百科rkStream and Read/Write functions.

The server creates a new thread for every client, the thread listen for any new messages.

Any better way?


You don't necessarily need to spawn a thread for each client. I'd investigate the Observer design pattern as it addresses the publish-subscribe problem, which is a good way to look at an instant messaging application, particularly if you want multiple listeners to one talker. Here's a good place to start: http://www.blackwasp.co.uk/Observer.aspx. This link discusses the Observer pattern and mentions instant messaging: http://www.oodesign.com/observer-pattern.html.

You may find that a single-threaded approach may be able to keep up with a lot of messages. Depending upon how you design you classes you may find it useful to put entire conversations in their own thread. You should also think about using queues to handle incoming and outgoing messages, with queue readers in their own thread as well.

Sounds like a fun project.


Try WCF. Here is a nice sample.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜