Beispiel #1
0
        public static void Main(string[] args)
        {
            bool running = true;

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                running  = false;
            };

            Server server = new Server();

            server.DebugOutput = true;

            server.MaxQueueSize = 10;

            server.SetInterrogationHandler(interrogationHandler, null);

            server.SetASDUHandler(asduHandler, null);

            server.Start();

            SimpleFile file = new SimpleFile(1, 30000, NameOfFile.TRANSPARENT_FILE);

            byte[] fileData = new byte[1025];

            for (int i = 0; i < 1025; i++)
            {
                fileData [i] = (byte)(i + 1);
            }

            file.AddSection(fileData);

            SimpleFile file2 = new SimpleFile(1, 30001, NameOfFile.TRANSPARENT_FILE);

            file2.AddSection(fileData);

            server.GetAvailableFiles().AddFile(file);
            server.GetAvailableFiles().AddFile(file2);

            ASDU newAsdu            = new ASDU(server.GetApplicationLayerParameters(), CauseOfTransmission.INITIALIZED, false, false, 0, 1, false);
            EndOfInitialization eoi = new EndOfInitialization(0);

            newAsdu.AddInformationObject(eoi);
            server.EnqueueASDU(newAsdu);

            while (running)
            {
                Thread.Sleep(100);
            }

            Console.WriteLine("Stop server");
            server.Stop();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            bool running = true;

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                running  = false;
            };

            Server server = new Server();

            server.DebugOutput = true;

            server.MaxQueueSize = 10;

            server.SetInterrogationHandler(interrogationHandler, null);

            server.SetASDUHandler(asduHandler, null);

            // Install a handler to allow file downloads (will be called when the master sends a file ready ASDU to anounce a file transfer)
            server.SetFileReadyHandler(delegate(object parameter, int ca, int ioa, NameOfFile nof, int lengthOfFile) {
                if ((ca == 1) && (ioa == 30001) && (nof == NameOfFile.TRANSPARENT_FILE))
                {
                    // Allow only files with a maximum of 5000 bytes
                    if (lengthOfFile > 5000)
                    {
                        Console.WriteLine("Deny file download. File too large");
                        return(null);
                    }
                    else
                    {
                        Console.WriteLine("Accept file download.");
                        return(new MyReceiver(lengthOfFile));
                    }
                }
                else
                {
                    Console.WriteLine("Deny file upload. Unknown file type.");
                    return(null);
                }
            }, null);

            server.Start();

            SimpleFile file = new SimpleFile(1, 30000, NameOfFile.TRANSPARENT_FILE);

            byte[] fileData = new byte[1025];

            for (int i = 0; i < 1025; i++)
            {
                fileData [i] = (byte)(i + 1);
            }

            file.AddSection(fileData);

            SimpleFile file2 = new SimpleFile(1, 30001, NameOfFile.TRANSPARENT_FILE);

            file2.AddSection(fileData);

            server.GetAvailableFiles().AddFile(file);
            server.GetAvailableFiles().AddFile(file2);

            ASDU newAsdu            = new ASDU(server.GetApplicationLayerParameters(), CauseOfTransmission.INITIALIZED, false, false, 0, 1, false);
            EndOfInitialization eoi = new EndOfInitialization(0);

            newAsdu.AddInformationObject(eoi);
            server.EnqueueASDU(newAsdu);

            while (running)
            {
                Thread.Sleep(100);
            }

            Console.WriteLine("Stop server");
            server.Stop();
        }