提交 e75525e2 编写于 作者: 若汝棋茗

优化UDP屏幕捕捉器

上级 901fc645
......@@ -119,7 +119,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LimitNumberOfConnectionsCon
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThrottlingConsoleApp", "examples\BlogsDemos\ThrottlingConsoleApp\ThrottlingConsoleApp.csproj", "{DD7848E5-3489-454E-BF37-49B6FE4C7F01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrafficCounterConsoleApp", "examples\BlogsDemos\TrafficCounterConsoleApp\TrafficCounterConsoleApp.csproj", "{82A783ED-11AD-407D-990B-A6AE9D557290}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrafficCounterConsoleApp", "examples\BlogsDemos\TrafficCounterConsoleApp\TrafficCounterConsoleApp.csproj", "{82A783ED-11AD-407D-990B-A6AE9D557290}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UDP屏幕捕捉器", "UDP屏幕捕捉器", "{8B9374B5-42D7-48C9-84C7-A560167F0D47}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScreenUdpSender", "examples\Udp简单示例\UDP屏幕捕捉器\ScreenUdpSender\ScreenUdpSender.csproj", "{791D316B-41D7-4B19-A25B-A58EBEA4E04A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScreenUdpReceiver", "examples\Udp简单示例\UDP屏幕捕捉器\ScreenUdpReceiver\ScreenUdpReceiver.csproj", "{EDAA9CD3-1474-4588-9E3B-E970CED20F0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -259,6 +265,14 @@ Global
{82A783ED-11AD-407D-990B-A6AE9D557290}.Debug|Any CPU.Build.0 = Debug|Any CPU
{82A783ED-11AD-407D-990B-A6AE9D557290}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82A783ED-11AD-407D-990B-A6AE9D557290}.Release|Any CPU.Build.0 = Release|Any CPU
{791D316B-41D7-4B19-A25B-A58EBEA4E04A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{791D316B-41D7-4B19-A25B-A58EBEA4E04A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{791D316B-41D7-4B19-A25B-A58EBEA4E04A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{791D316B-41D7-4B19-A25B-A58EBEA4E04A}.Release|Any CPU.Build.0 = Release|Any CPU
{EDAA9CD3-1474-4588-9E3B-E970CED20F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDAA9CD3-1474-4588-9E3B-E970CED20F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDAA9CD3-1474-4588-9E3B-E970CED20F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDAA9CD3-1474-4588-9E3B-E970CED20F0F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -317,6 +331,9 @@ Global
{8452EA31-F7BB-4897-8881-F3EE3F82049A} = {EB38E883-88AF-4E4C-9DCD-FAEBD8A20968}
{DD7848E5-3489-454E-BF37-49B6FE4C7F01} = {EB38E883-88AF-4E4C-9DCD-FAEBD8A20968}
{82A783ED-11AD-407D-990B-A6AE9D557290} = {EB38E883-88AF-4E4C-9DCD-FAEBD8A20968}
{8B9374B5-42D7-48C9-84C7-A560167F0D47} = {F4D798A3-8D65-4750-9552-B02BCE081508}
{791D316B-41D7-4B19-A25B-A58EBEA4E04A} = {8B9374B5-42D7-48C9-84C7-A560167F0D47}
{EDAA9CD3-1474-4588-9E3B-E970CED20F0F} = {8B9374B5-42D7-48C9-84C7-A560167F0D47}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB787235-A13A-4A3D-B5A8-5DFEB6511EEE}
......
......@@ -6,6 +6,9 @@ using TouchSocket.Sockets;
namespace ScreenUdpReceiver
{
/// <summary>
/// 本程序源码由网友“木南白水”提供。
/// </summary>
public partial class Form1 : Form
{
UdpSession udpSession;
......@@ -26,8 +29,8 @@ namespace ScreenUdpReceiver
};
udpSession.Setup(new TouchSocketConfig()
.SetBindIPHost(new IPHost("127.0.0.1:7790"))
.SetBufferLength(1024 * 1024)
.SetUdpDataHandlingAdapter(() => { return new UdpPackageAdapter() { MaxPackageSize = 1024 * 1024 }; })
.SetBufferLength(1024 * 64)
.SetUdpDataHandlingAdapter(() => { return new UdpPackageAdapter() { MaxPackageSize = 1024 * 1024, MTU = 1024 * 10 }; })
).Start();
}
catch (Exception ex)
......
......@@ -28,28 +28,74 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.button1 = new System.Windows.Forms.Button();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// timer1
// button1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
this.button1.Location = new System.Drawing.Point(268, 43);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(150, 46);
this.button1.TabIndex = 0;
this.button1.Text = "启动";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(111, 49);
this.numericUpDown1.Maximum = new decimal(new int[] {
20,
0,
0,
0});
this.numericUpDown1.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(134, 38);
this.numericUpDown1.TabIndex = 1;
this.numericUpDown1.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(33, 51);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 31);
this.label1.TabIndex = 2;
this.label1.Text = "FPS:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleDimensions = new System.Drawing.SizeF(14F, 31F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(1600, 821);
this.Controls.Add(this.label1);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.button1);
this.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.Name = "Form1";
this.Text = "Sender 感谢若汝棋茗大佬的无私奉献 -xfdl 监听地址127.0.0.1:7789,发送地址127.0.0.1:7790";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label1;
}
}
......@@ -3,6 +3,7 @@ using System.Drawing;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using TouchSocket.Core.ByteManager;
using TouchSocket.Core.Config;
......@@ -10,6 +11,9 @@ using TouchSocket.Sockets;
namespace ScreenUdpSender
{
/// <summary>
/// 本程序源码由网友“木南白水”提供。
/// </summary>
public partial class Form1 : Form
{
UdpSession udpSession;
......@@ -18,34 +22,19 @@ namespace ScreenUdpSender
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
try
{
udpSession = new UdpSession();
Thread m_thread;
udpSession.Setup(
new TouchSocketConfig()
.SetBindIPHost(new IPHost(7789))
.SetBufferLength(1024 * 1024)
.SetUdpDataHandlingAdapter(() => { return new UdpPackageAdapter() { MaxPackageSize = 1024 * 1024 }; })
).Start();
}
catch (Exception ex)
private void Tick()
{
while (true)
{
MessageBox.Show($"错误:{ex.Message},程序将退出");
Environment.Exit(0);
byte[] byteArray = ImageToByte(getScreen());
ByteBlock bb = new ByteBlock(byteArray);
udpSession.Send(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7790), bb);
Thread.Sleep((int)(1000.0/(int)this.numericUpDown1.Value));
}
}
private void timer1_Tick(object sender, EventArgs e)
{
byte[] byteArray = ImageToByte(getScreen());
ByteBlock bb = new ByteBlock(byteArray);
udpSession.Send(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7790), bb);
}
#region 屏幕和光标获取
[DllImport("user32.dll")]
......@@ -119,5 +108,29 @@ namespace ScreenUdpSender
return image;
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
try
{
udpSession = new UdpSession();
udpSession.Setup(
new TouchSocketConfig()
.SetBindIPHost(new IPHost(7789))
.SetBufferLength(1024 * 64)
.SetUdpDataHandlingAdapter(() => { return new UdpPackageAdapter() { MaxPackageSize = 1024 * 1024, MTU = 1024 * 10 }; })
).Start();
m_thread = new Thread(Tick);
m_thread.IsBackground = true;
m_thread.Start();
}
catch (Exception ex)
{
MessageBox.Show($"错误:{ex.Message},程序将退出");
Environment.Exit(0);
}
}
}
}
......@@ -57,7 +57,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册