I am currently trying to make a little server, but I have encountered a problem, what I belive is a deadlock. And my question is how to actually avoid deadlock problem in C# Tcp? Let me show you something.
public static void SendString (TcpClient klient, string message) { byte[] byteBuffer = Encoding.UTF8.GetBytes(message); NetworkStream netStream = klient.GetStream(); netStream.Write(byteBuffer, 0, byteBuffer.Length); netStream.Write(new byte[] { separator }, 0, sizeof(byte)); netStream.Flush(); } public static string AcceptString (TcpClient klient) { List<int> buffer = new List<int>(); NetworkStream stream = klient.GetStream(); int readByte; while ((readByte = stream.ReadByte()) != 0) buffer.Add(readByte); return Encoding.UTF8.GetString(buffer.Select<int, byte>(b => (byte)b).ToArray(), 0, buffer.Count); } Can deadlock occur when both sides try to call SendString() (on each other)? And if not, what actually causes deadlock? I mean I know what deadlock is (when both sides are waiting for action of the other side) but what it actually means in C# networking?