internal Listener(ServerAssociationParameters parameters, StartAssociation acceptor) { ListenerInfo info = new ListenerInfo(); info.Parameters = parameters; info.StartDelegate = acceptor; _applications.Add(parameters.CalledAE, info); _ipEndPoint = parameters.LocalEndPoint; }
/// <summary> /// Method called when receiving an association request. /// </summary> /// <param name="association"></param> protected override void OnReceiveAssociateRequest(ServerAssociationParameters association) { ListenerInfo info; if (!_appList.TryGetValue(association.CalledAE, out info)) { Platform.Log(LogLevel.Error, "Rejecting association from {0}: Invalid Called AE Title ({1}).", association.CallingAE, association.CalledAE); SendAssociateReject(DicomRejectResult.Permanent, DicomRejectSource.ServiceProviderACSE, DicomRejectReason.CalledAENotRecognized); return; } // Populate the AssociationParameters properly association.ReadTimeout = info.Parameters.ReadTimeout; association.ReceiveBufferSize = info.Parameters.ReceiveBufferSize; association.WriteTimeout = info.Parameters.WriteTimeout; association.SendBufferSize = info.Parameters.SendBufferSize; association.RemoteEndPoint = _socket.RemoteEndPoint as IPEndPoint; association.LocalEndPoint = _socket.LocalEndPoint as IPEndPoint; // Setup Socketoptions based on the user's settings SetSocketOptions(association); // Select the presentation contexts bool anyValidContexts = NegotiateAssociation(association, info.Parameters); if (!anyValidContexts) { Platform.Log(LogLevel.Error, "Rejecting association from {0}: No valid presentation contexts.", association.CallingAE); SendAssociateReject(DicomRejectResult.Permanent, DicomRejectSource.ServiceProviderACSE, DicomRejectReason.NoReasonGiven); return; } _appList = null; try { _handler = info.StartDelegate(this, association); _handler.OnReceiveAssociateRequest(this, association); } catch (Exception e) { OnUserException(e, "Unexpected exception on OnReceiveAssociateRequest or StartDelegate"); } }
public static bool Listen(ServerAssociationParameters parameters, StartAssociation acceptor) { lock (_syncLock) { Listener theListener; if (_listeners.TryGetValue(parameters.LocalEndPoint, out theListener)) { ListenerInfo info = new ListenerInfo(); info.StartDelegate = acceptor; info.Parameters = parameters; if (theListener._applications.ContainsKey(parameters.CalledAE)) { Platform.Log(LogLevel.Error, "Already listening with AE {0} on {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); return(false); } theListener._applications.Add(parameters.CalledAE, info); Platform.Log(LogLevel.Info, "Starting to listen with AE {0} on existing port {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } else { theListener = new Listener(parameters, acceptor); if (!theListener.StartListening()) { Platform.Log(LogLevel.Error, "Unexpected error starting to listen on {0}", parameters.LocalEndPoint.ToString()); return(false); } _listeners[parameters.LocalEndPoint] = theListener; theListener.StartThread(); Platform.Log(LogLevel.Info, "Starting to listen with AE {0} on port {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } return(true); } }
public static bool StopListening(ServerAssociationParameters parameters) { lock (_syncLock) { Listener theListener; if (_listeners.TryGetValue(parameters.LocalEndPoint, out theListener)) { if (theListener._applications.ContainsKey(parameters.CalledAE)) { theListener._applications.Remove(parameters.CalledAE); if (theListener._applications.Count == 0) { // Cleanup the listener _listeners.Remove(parameters.LocalEndPoint); theListener.StopThread(); theListener.Dispose(); } Platform.Log(LogLevel.Info, "Stopping listening with AE {0} on {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } else { Platform.Log(LogLevel.Error, "Unable to stop listening on AE {0}, assembly was not listening with this AE.", parameters.CalledAE); return(false); } } else { Platform.Log(LogLevel.Error, "Unable to stop listening, assembly was not listening on end point {0}.", parameters.LocalEndPoint.ToString()); return(false); } return(true); } }
/// <summary> /// Stop listening for incoming associations. /// </summary> /// <remarks> /// <para> /// Note that <see cref="StartListening"/> can be called multiple times with different association /// parameters. /// </para> /// </remarks> /// <param name="parameters">The parameters to stop listening on.</param> public static void StopListening(ServerAssociationParameters parameters) { Listener.StopListening(parameters); }
/// <summary> /// Start listening for incoming associations. /// </summary> /// <remarks> /// <para> /// Note that StartListening can be called multiple times with different association parameters. /// </para> /// </remarks> /// <param name="parameters">The parameters to use when listening for associations.</param> /// <param name="acceptor">A delegate to be called to return a class instance that implements /// the <see cref="IDicomServerHandler"/> interface to handle an incoming association.</param> /// <returns><i>true</i> on success, <i>false</i> on failure</returns> public static bool StartListening(ServerAssociationParameters parameters, StartAssociation acceptor) { return(Listener.Listen(parameters, acceptor)); }