Advertisement
Guest User

Untitled

a guest
Dec 24th, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. public void SendPrint()
  2. {
  3. byte[] sendBytes;
  4. sendBytes = BmpToBytes(getScreen()); //Convert image to bytes array
  5. streamWriter.WriteLine(sendBytes.Length); //Send the binary header
  6. streamWriter.Flush();
  7. networkStream.Write(sendBytes, 0, sendBytes.Length); //Send the image bytes
  8. networkStream.Flush();
  9. }
  10.  
  11. private void ReceivingScreens()
  12. {
  13. while (ReceivePrint)
  14. {
  15. strInput.Append("{SCREENDESKTOP}");
  16. streamWriter.WriteLine(strInput); //Send the request
  17. streamWriter.Flush();
  18. strInput.Remove(0, strInput.Length);
  19. int size;
  20. try
  21. {
  22. //get the image size
  23. size = int.Parse(streamReader.ReadLine()); **//Error happens here**
  24. }
  25. catch
  26. {
  27. MessageBox.Show("WRONG");
  28. return;
  29. }
  30. byte[] TOTAL = new byte[0];
  31. byte[] parcial;
  32. while (TOTAL.Length < size)
  33. {
  34. //Get lenght of some image bytes
  35. parcial = new byte[ConexaoServer.ReceiveBufferSize];
  36. //Get some image bytes
  37. networkStream.Read(parcial, 0, ConexaoServer.ReceiveBufferSize);
  38. //Joins all bytes
  39. TOTAL = JoinBytes(TOTAL, parcial);
  40. networkStream.Flush();
  41. System.Threading.Thread.Sleep(100);
  42. }
  43. try
  44. {
  45. picdesktop.Image = BytesToImg(TOTAL); //Convert bytes to image
  46. }
  47. catch (Exception exp)
  48. {
  49. MessageBox.Show(exp.Message);
  50. }
  51. Application.DoEvents();
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement