Komunikation mit server erstellt
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -53,6 +54,11 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Service1.resx">
|
||||
<DependentUpon>Service1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
Generated
+9
-2
@@ -28,10 +28,17 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
this.ServiceName = "Service1";
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||
//
|
||||
// Service1
|
||||
//
|
||||
this.ServiceName = "NetMonitorServer";
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Timer timer1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,22 +6,52 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
public partial class Service1 : ServiceBase
|
||||
{
|
||||
private Thread ot;
|
||||
public Service1()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.ot = new Thread(new ThreadStart(overwatch));
|
||||
this.ot.IsBackground = true;
|
||||
this.ot.Start();
|
||||
}
|
||||
private static void overwatch()
|
||||
{
|
||||
UdpClient client = new UdpClient(34523);
|
||||
IPEndPoint iep = new IPEndPoint(IPAddress.Loopback, 0);
|
||||
while (true)
|
||||
{
|
||||
if (Thread.CurrentThread.ThreadState == System.Threading.ThreadState.AbortRequested)
|
||||
{
|
||||
client.Close();
|
||||
break;
|
||||
}
|
||||
byte[] data = client.Receive(ref iep);
|
||||
string text = Encoding.UTF8.GetString(data);
|
||||
switchCommand(text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void switchCommand(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
}
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
this.ot.Start();
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
this.ot.Abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user