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:
- Could you confirm that the example is wrong?
- How should it be done, is it enough to lock the broadcast method (mark it as a critical section)?
- Could you recommend some socket communication tutorials (.Net preferred)?