From e6b8e09e9102fb8bf9971a2cfee0e526989779f6 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 17 Jan 2017 21:13:05 +0100 Subject: [PATCH] - .NET API: fixed server side bug with connection indication handler --- dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs | 8 +++++++- dotnet/example1/Main.cs | 9 +++++++-- dotnet/server1/Program.cs | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs index 5dde698..b19835c 100644 --- a/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs +++ b/dotnet/IEC61850forCSharp/IEC61850ServerAPI.cs @@ -779,11 +779,15 @@ namespace IEC61850 // } //} + private InternalConnectionHandler internalConnectionHandler = null; /// Start MMS server public void Start(int tcpPort) { - IedServer_setConnectionIndicationHandler (self, connectionIndicationHandler, IntPtr.Zero); + if (internalConnectionHandler == null) + internalConnectionHandler = new InternalConnectionHandler (connectionIndicationHandler); + + IedServer_setConnectionIndicationHandler (self, internalConnectionHandler, IntPtr.Zero); IedServer_start(self, tcpPort); } @@ -801,6 +805,7 @@ namespace IEC61850 public void Stop() { IedServer_stop(self); + internalConnectionHandler = null; } /// @@ -811,6 +816,7 @@ namespace IEC61850 { IedServer_destroy(self); self = IntPtr.Zero; + internalConnectionHandler = null; } public bool IsRunning() diff --git a/dotnet/example1/Main.cs b/dotnet/example1/Main.cs index 24de9eb..eb70ce5 100644 --- a/dotnet/example1/Main.cs +++ b/dotnet/example1/Main.cs @@ -17,14 +17,19 @@ namespace example1 if (args.Length > 0) hostname = args[0]; else - hostname = "10.0.2.2"; + hostname = "127.0.0.1"; + + int port = 102; + + if (args.Length > 1) + port = Int32.Parse(args [1]); Console.WriteLine("Connect to " + hostname); try { - con.Connect(hostname, 102); + con.Connect(hostname, port); List serverDirectory = con.GetServerDirectory(false); diff --git a/dotnet/server1/Program.cs b/dotnet/server1/Program.cs index 52d8fc1..1776257 100644 --- a/dotnet/server1/Program.cs +++ b/dotnet/server1/Program.cs @@ -42,6 +42,8 @@ namespace server1 iedServer.Start (102); Console.WriteLine ("Server started"); + GC.Collect (); + while (running) { Thread.Sleep (1); }