From 96fe859f9ac715d4d85acedaf613109d3b287c98 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Mon, 26 Apr 2010 10:46:03 +0000 Subject: [PATCH] Komunikation mit server erstellt --- NetMonitorClient/Form1.Designer.cs | 16 +++++++++---- NetMonitorClient/Form1.cs | 3 +-- NetMonitorClient/ServiceControl.cs | 21 +++++++++++++---- NetMonitorServer/NetMonitorServer.csproj | 6 +++++ NetMonitorServer/Service1.Designer.cs | 11 +++++++-- NetMonitorServer/Service1.cs | 30 ++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 13 deletions(-) diff --git a/NetMonitorClient/Form1.Designer.cs b/NetMonitorClient/Form1.Designer.cs index 5427bae..cb96df0 100644 --- a/NetMonitorClient/Form1.Designer.cs +++ b/NetMonitorClient/Form1.Designer.cs @@ -30,7 +30,6 @@ { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Netzmonitor)); - this.serviceController1 = new System.ServiceProcess.ServiceController(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); @@ -50,8 +49,7 @@ this.trayMenuNetzwerk = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout(); - this.trayMenu.SuspendLayout(); - this.SuspendLayout(); + this.SuspendLayout(); // // menuStrip1 // @@ -167,6 +165,15 @@ this.trayIcon.Visible = true; this.trayIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.trayIcon_MouseDoubleClick); // + // trayMenu + // + this.trayMenu.Name = "trayMenu"; + // + // trayMenuNetzwerk + // + this.trayMenuNetzwerk.Name = "trayMenuNetzwerk"; + this.trayMenuNetzwerk.Size = new System.Drawing.Size(32, 19); + // // Netzmonitor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -182,14 +189,13 @@ this.menuStrip1.PerformLayout(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); - this.trayMenu.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); } #endregion - private System.ServiceProcess.ServiceController serviceController1; + private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; diff --git a/NetMonitorClient/Form1.cs b/NetMonitorClient/Form1.cs index 7726622..2fa52cb 100644 --- a/NetMonitorClient/Form1.cs +++ b/NetMonitorClient/Form1.cs @@ -16,8 +16,7 @@ namespace NetMonitorClient { InitializeComponent(); InitNetworks(); - this.serviceController1.ServiceName = "NetMonitorServer"; - this.sc = new ServiceControl(this.serviceController1); + this.sc = new ServiceControl("NetMonitorServer"); } private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e) diff --git a/NetMonitorClient/ServiceControl.cs b/NetMonitorClient/ServiceControl.cs index c7835f1..cf64a60 100644 --- a/NetMonitorClient/ServiceControl.cs +++ b/NetMonitorClient/ServiceControl.cs @@ -2,20 +2,33 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.ServiceProcess; +using System.Net.Sockets; +using System.Net; namespace NetMonitorClient { class ServiceControl { - private System.ServiceProcess.ServiceController sc; - public ServiceControl(System.ServiceProcess.ServiceController Controller) + private UdpClient client; + private IPEndPoint rep; //remoteEndPoint + public ServiceControl(string name) { - this.sc = Controller; + ServiceController sc = new ServiceController(); + sc.ServiceName = name; + //if (sc.Status != ServiceControllerStatus.Running) + //{ + // sc.Start(); + //} + this.client = new UdpClient(); + this.rep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523); } internal void setNetworkAuto() { - throw new NotImplementedException(); + byte[] data = Encoding.UTF8.GetBytes("NET AUTO"); + this.client.Send(data, data.Length, this.rep); + //throw new NotImplementedException(); } internal void setNetworkIp(string ip, string subnet, string gateway) diff --git a/NetMonitorServer/NetMonitorServer.csproj b/NetMonitorServer/NetMonitorServer.csproj index 95102d8..12b0609 100644 --- a/NetMonitorServer/NetMonitorServer.csproj +++ b/NetMonitorServer/NetMonitorServer.csproj @@ -36,6 +36,7 @@ + @@ -53,6 +54,11 @@ + + + Service1.cs + +