I have client server project. i have a problem in sending data from server to clients.
private bool SendPack(object client, string data)
{
lock (this)
{
try
{
NetworkStream clientStream = tcpServer.GetStream();
byte[] Pack= ClsEncryption.GetEncrypt(data);
clientStream.Write(Pack, 0, Pack.Length);
clientStream.Flush();
return true;
}
catch
{
return false;
}
}
}
although i use lock, when write command runs, everything ruin. i mean nothing send and the write does not return(like blocking). should i use asynch methods by using beginwrite or not? how can i check if the networkstream is ready to write and would not block. i use clientstream.canwrite, but it was not useful.
I need the fastest and most reliable way to send data. Any Idea?