public static void run() { NetworkStream ns = clientSocket.GetStream(); byte[] outstream = null; //sent mac now running loop until termination while (running) { String line = ReadMessage(ns); Console.WriteLine("Got " + line); Console.WriteLine("Read someting : "+line); if (line.Equals("getSS")) { string len_str = null; Boolean flaggy = true; Console.WriteLine("Got screenshot request"); //server asking for image , ironic that the client is serving.lol Bitmap img = null; try { img = ScreenShot.Capture(0, 0, 1366, 768); outstream = img.ToByteArray(ImageFormat.Png); //sending image length Console.WriteLine("LENGTH:" + outstream.Length); //Sending length len_str = outstream.Length + ""; flaggy = true; } catch (Exception) { flaggy = false; len_str = -1+""; } String output = String.Format("{0,10}", len_str); byte[] arr = GetBytes(output); ns.Write(arr, 0, arr.Length); //Sending image Thread.Sleep(1); // Write only if the image is captured properly if (flaggy == true) { ns.Write(outstream, 0, outstream.Length); } } else if (line.Equals("getStat")) { XDocument doc = getProcessesXML(); string s = doc.ToString(); WriteMessage(ns,s); } else if (line.Equals("getMAC")) { //sending MAC address string mac = GetMACAddress(); Console.Write("MAC IS : "+mac);// \n for delimiting the strings WriteMessage(ns, mac); } } }
public static void CaptureAndSave(int x, int y, int width, int height, string imagePath) { Bitmap myImage = ScreenShot.Capture(x, y, width, height); myImage.Save(imagePath, ImageFormat.Png); }