DicomObjects.NET.8.48 Documentation
DicomObjects Namespace / DicomServer Class / UnlistenAll Method
Example

In This Topic
    UnlistenAll Method
    In This Topic
    Close all "Listening" TCP ports for incoming DICOM Connections
    Syntax
    'Declaration
     
    
    Public Sub UnlistenAll() 
    public void UnlistenAll()
    Remarks

    Since more than one port may be active simultaneously, this method is designed to close all "Listening" socket.

    For more information see Unlisten.

    Example
    DicomServer server = new DicomServer();
                
    // Handle incoming DICOM association requests
    server.AssociationRequest += (sender, e) =>
    {
        Console.WriteLine($"Incoming DICOM association request from {e.Association.CallingAET}");
    };
                
    int port = 104;
    int securePort = 2762;
                
    // replace with actual addresses
    string address = "192.168.xx.xxx";
    string ipv6address = "fe80::xxxx:xxxx:xxxx:xxxx%X";
    string address2 = "127.0.0.1";
                
    server.Listen(securePort, AddressFamily.InterNetwork, MinimalWindowsServer.GetDecryptedStream);
    server.Listen(securePort, ipv6address, AddressFamily.InterNetworkV6, MinimalWindowsServer.GetDecryptedStream);
    server.Listen(port, address);
    server.Listen(port, address2);
                
    // all 4 listeners are unlistened
    server.UnlistenAll();
                
    // Basic TLSAcceptor Implementation
    class MinimalWindowsServer {
        internal static Stream GetDecryptedStream(Stream EncryptedStream, string RemoteAddress, int LocalPort)
        {
            var Certificate = new X509Certificate2("C:\\Path\\To\\client.pfx", "password"); // replace with your actual certificate and password
                
            SslStream ssl = new SslStream(EncryptedStream, false, ValidateWindowsCertificate);
            ssl.AuthenticateAsServer(Certificate, true, SslProtocols.Tls, false);
            return ssl;
        }
                
        //this one is for the SCP to validate the client's certificate (if provided)
        public static bool ValidateWindowsCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            // Accept all connections without a client certificate (for testing)
            if (sslPolicyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable))
                return true;
                
            return true;
        }
    }
    Requirements

    Target Platforms: .NET CLR 4.8 or higher

    See Also