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.SetLocalPort(2405); server.SetInterrogationHandler(interrogationHandler, null); server.SetASDUHandler(asduHandler, null); if (1 == rfiletable()) { return; } server.Start(); ASDU newAsdu = new ASDU(server.GetApplicationLayerParameters(), CauseOfTransmission.INITIALIZED, false, false, 0, 1, false); EndOfInitialization eoi = new EndOfInitialization(0); newAsdu.AddInformationObject(eoi); server.EnqueueASDU(newAsdu); int waitTime = 1000; while (running) { Thread.Sleep(1000); if (waitTime > 0) { waitTime -= 100; } else { newAsdu = new ASDU(server.GetApplicationLayerParameters(), CauseOfTransmission.PERIODIC, false, false, 1, 1, true); ToServer(ref newAsdu); rfile( ); server.EnqueueASDU(newAsdu); waitTime = 1000; } } Console.WriteLine("Stop server"); server.Stop(); }
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.EnqueueMode = EnqueueMode.REMOVE_OLDEST; server.SetInterrogationHandler(interrogationHandler, null); server.SetASDUHandler(asduHandler, null); server.Start(); ASDU newAsdu = new ASDU(server.GetApplicationLayerParameters(), CauseOfTransmission.INITIALIZED, false, false, 0, 1, false); EndOfInitialization eoi = new EndOfInitialization(0); newAsdu.AddInformationObject(eoi); server.EnqueueASDU(newAsdu); int waitTime = 1000; while (running) { Thread.Sleep(100); if (waitTime > 0) { waitTime -= 100; } else { newAsdu = new ASDU(server.GetApplicationLayerParameters(), CauseOfTransmission.PERIODIC, false, false, 0, 1, false); newAsdu.AddInformationObject(new MeasuredValueScaled(110, -1, new QualityDescriptor())); server.EnqueueASDU(newAsdu); waitTime = 1000; } } Console.WriteLine("Stop server"); server.Stop(); }
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(); }
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(); }
public static void Main(string[] args) { bool running = true; Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; running = false; }; // Own certificate has to be a pfx file that contains the private key X509Certificate2 ownCertificate = new X509Certificate2("server.pfx"); // Create a new security information object to configure TLS TlsSecurityInformation secInfo = new TlsSecurityInformation(ownCertificate); // Add allowed client certificates - not required when AllowOnlySpecificCertificates == false secInfo.AddAllowedCertificate(new X509Certificate2("client1.cer")); secInfo.AddAllowedCertificate(new X509Certificate2("client2.cer")); // Add a CA certificate to check the certificate provided by the server - not required when ChainValidation == false secInfo.AddCA(new X509Certificate2("root.cer")); // Check if the certificate is signed by a provided CA secInfo.ChainValidation = true; // Check that the shown client certificate is in the list of allowed certificates secInfo.AllowOnlySpecificCertificates = true; // Use constructor with security information object, this will force the connection using TLS (using TCP port 19998) Server server = new Server(secInfo); server.DebugOutput = true; server.MaxQueueSize = 10; server.SetInterrogationHandler(interrogationHandler, null); server.SetASDUHandler(asduHandler, null); server.Start(); ASDU newAsdu = new ASDU(server.GetConnectionParameters(), CauseOfTransmission.INITIALIZED, false, false, 0, 1, false); EndOfInitialization eoi = new EndOfInitialization(0); newAsdu.AddInformationObject(eoi); server.EnqueueASDU(newAsdu); int waitTime = 1000; while (running) { Thread.Sleep(100); if (waitTime > 0) { waitTime -= 100; } else { newAsdu = new ASDU(server.GetConnectionParameters(), CauseOfTransmission.PERIODIC, false, false, 2, 1, false); newAsdu.AddInformationObject(new MeasuredValueScaled(110, -1, new QualityDescriptor())); server.EnqueueASDU(newAsdu); waitTime = 1000; } } Console.WriteLine("Stop server"); server.Stop();; }