Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Simple chat server example

Tags:

c#

sockets

I was looking for the simple step by step communication tutorial for .Net programmers. After some Google queries, I have found the "CSharp Communications" code collections at net-informations.com. It looked quite good as long as I reached the "How to C# Chat Server" example.

Authors propose multithreaded server with the HashTable container to keep all connections in the shared memory at the server side. According to MSDN documentation TcpClient and NetworkStream classes used for broadcast messages are not thread safe, while the example uses them from multiple server threads.

My questions are:

  1. Could you confirm that the example is wrong?
  2. How should it be done, is it enough to lock the broadcast method (mark it as a critical section)?
  3. Could you recommend some socket communication tutorials (.Net preferred)?
like image 603
kuszi Avatar asked Oct 29 '25 13:10

kuszi


1 Answers

It is not perfect as I wrote it almost 7 years ago, but it is covering and will give you good understanding regarding the field of TCP communications:

Generic TCP/IP Client Server

like image 130
G.Y Avatar answered Oct 31 '25 11:10

G.Y



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!