Esempio n. 1
0
        public void ConnectionHandler()
        {
            IedModel iedModel = ConfigFileParser.CreateModelFromConfigFile("../../model.cfg");

            int handlerCalled   = 0;
            int connectionCount = 0;

            IedServer iedServer = new IedServer(iedModel);

            string ipAddress = null;

            iedServer.SetConnectionIndicationHandler(delegate(IedServer server, ClientConnection clientConnection, bool connected, object parameter) {
                handlerCalled++;
                if (connected)
                {
                    connectionCount++;
                }
                else
                {
                    connectionCount--;
                }

                ipAddress = clientConnection.GetPeerAddress();
            }, null);

            iedServer.Start(10002);

            IedConnection con1 = new IedConnection();

            con1.Connect("localhost", 10002);

            Assert.AreEqual(1, handlerCalled);
            Assert.AreEqual(1, connectionCount);

            IedConnection con2 = new IedConnection();

            con2.Connect("localhost", 10002);

            Assert.AreEqual(2, handlerCalled);
            Assert.AreEqual(2, connectionCount);

            con1.Abort();
            con2.Abort();

            Assert.AreEqual(4, handlerCalled);
            Assert.AreEqual(0, connectionCount);

            Assert.AreEqual("127.0.0.1:", ipAddress.Substring(0, 10));

            iedServer.Stop();

            iedServer.Dispose();
        }