Hello All!
I write a client - server utility which sends a xml document through network and does some work on the server side with it. I use a NetworkStream object as a parameter for "Save" and "Load" methods of a XDocument object.
on the client side:
public static void StartClient(XDocument NewInit)
{
TcpClient tcpClient = new TcpClient();
NetworkStream stream = tcpClient.GetStream();
NewInit.Save(stream);
}
on the server side:
NetworkStream stream = tcpClient.GetStream();
XDocument NewInit = XDocument.Load(stream);
It works fine. But I need to do some work with the received document and send an answer back to the client. I try to do this using "Write" metod of the strim.
On the server side, immediately after the strings above:
byte[] msg = Encoding.ASCII.GetBytes("Object created!");
stream.Write(msg, 0, msg.Length);
On the client side, immediately after saving xml into the stream:
byte[] bytes = new byte[1024];
int bytesRec = stream.Read(bytes, 0, bytes.Length);
textBox.Text = Encoding.ASCII.GetString(bytes, 0, bytesRec);
That is where my program freezes. And not only the client does not get the answer, but the xml is not being received either.
Please, tell me how to do it right.