public void SendPrint()
{
byte[] sendBytes;
sendBytes = BmpToBytes(getScreen()); //Convert image to bytes array
streamWriter.WriteLine(sendBytes.Length); //Send the binary header
streamWriter.Flush();
networkStream.Write(sendBytes, 0, sendBytes.Length); //Send the image bytes
networkStream.Flush();
}
private void ReceivingScreens()
{
while (ReceivePrint)
{
strInput.Append("{SCREENDESKTOP}");
streamWriter.WriteLine(strInput); //Send the request
streamWriter.Flush();
strInput.Remove(0, strInput.Length);
int size;
try
{
//get the image size
size = int.Parse(streamReader.ReadLine()); **//Error happens here**
}
catch
{
MessageBox.Show("WRONG");
return;
}
byte[] TOTAL = new byte[0];
byte[] parcial;
while (TOTAL.Length < size)
{
//Get lenght of some image bytes
parcial = new byte[ConexaoServer.ReceiveBufferSize];
//Get some image bytes
networkStream.Read(parcial, 0, ConexaoServer.ReceiveBufferSize);
//Joins all bytes
TOTAL = JoinBytes(TOTAL, parcial);
networkStream.Flush();
System.Threading.Thread.Sleep(100);
}
try
{
picdesktop.Image = BytesToImg(TOTAL); //Convert bytes to image
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
Application.DoEvents();
}
}