4

I would like to write a c# server that will act roughly as a chat server ( clients are connected for a while, same message could be dispatched to many clients , .... ).

I was wondering if you can give me some hints to start (what kind of architecture ( threads by clients / iocp / asynchronous / ...) that will allow to scale well ( should be able to handle thousands of simultaneous connections ) ).

samoz
  • 56,849
  • 55
  • 141
  • 195
Dave
  • 1,835
  • 4
  • 26
  • 44
  • Is this meant for learning (i.e. making a multi-threaded chat server is great for learning how to work with networks and scaling for multiple connections) or for production? – configurator Jun 05 '09 at 17:31
  • I am interested to learn the good practice to write prod quality server . But the goal of my project is only intented to get a deeper understanding of the different mechanism . – Dave Jun 05 '09 at 20:29
  • If your goal is to understand the mechanism, I'd go with TcpClient. They're quite simple to use, and they expose pretty much exactly what is going on. KClough's suggested tutorial shows you how to use them. – configurator Jun 07 '09 at 02:14

4 Answers4

2

Here is a tutorial that will get you off to a good start.

Looks like it uses a threaded implementation so it should scale well.

Building a Chat Server and a Chat Client

KClough
  • 2,079
  • 2
  • 21
  • 29
2

Here is an example using WCF: http://www.codeproject.com/KB/WCF/WCFWPFChat.aspx

Hopefully you would not have to deal with raw sockets by using WCF, it would be interesting to see if WCF could handle the thousands of connections though...

jjxtra
  • 20,415
  • 16
  • 100
  • 140
1

If you need scalability of the kind you are talking about, IOCP is the only way to go.

There are some pitfalls to be avoided though, so read my detailed answer on: How to write a scalable Tcp/Ip based server in conjunction with the accepted answer on the same question.

Community
  • 1
  • 1
jerryjvl
  • 19,723
  • 7
  • 40
  • 55
0

This might be a good place to start: http://www.dreamincode.net/forums/showtopic33396.htm

Irwin
  • 12,551
  • 11
  • 67
  • 97