pynetdicom.transport.AssociationServer#
- class pynetdicom.transport.AssociationServer(ae: ApplicationEntity, address: tuple[str, int] | tuple[str, int, int, int], ae_title: str, contexts: list[PresentationContext], ssl_context: ssl.SSLContext | None = None, evt_handlers: list[tuple[NotificationEvent | InterventionEvent, Callable] | tuple[NotificationEvent | InterventionEvent, Callable, list[Any]]] | None = None, request_handler: Callable[[...], BaseRequestHandler] | None = None)[source]#
An Association server implementation.
Any attempts to connect will be assumed to be from association requestors.
The server should be started with
serve_forever(poll_interval), where poll_interval is the timeout (in seconds) that theselect.select()call will block for (default0.5). A value of0specifies a poll and never blocks. A value ofNoneblocks until a connection is ready.Changed in version 3.0: Added support for IPv6.
- ae#
The parent AE that is running the server.
- Type:
- server_address#
The
(host: str, port: int)or(host: str, port: int, flowinfo: int, scope_id: int)that the server is running on.
- __init__(ae: ApplicationEntity, address: tuple[str, int] | tuple[str, int, int, int], ae_title: str, contexts: list[PresentationContext], ssl_context: ssl.SSLContext | None = None, evt_handlers: list[tuple[NotificationEvent | InterventionEvent, Callable] | tuple[NotificationEvent | InterventionEvent, Callable, list[Any]]] | None = None, request_handler: Callable[[...], BaseRequestHandler] | None = None) None[source]#
Create a new
AssociationServer, bind a socket and start listening.- Parameters:
ae (ae.ApplicationEntity) – The parent AE that’s running the server.
address (tuple[str, int] | tuple[str, int, int, int]) – The
(host: str, port: int)or(host: str, port: int, flowinfo: int, scope_id: int)that the server should run on.ae_title (str) – The AE title of the SCP.
contexts (list of presentation.PresentationContext) – The SCPs supported presentation contexts.
ssl_context (ssl.SSLContext, optional) – If TLS is to be used then this should be the
ssl.SSLContextused to wrap the client sockets, otherwise ifNonethen no TLS will be used (default).evt_handlers (list of 2- or 3-tuple, optional) – A list of
(event, callable)or(event, callable, args), the callable function to run when event occurs and the optional extra args to pass to the callable.request_handler (type) – The request handler class; an instance of this class is created for each request. Should be a subclass of
BaseRequestHandler.
Methods
__init__(ae, address, ae_title, contexts[, ...])Create a new
AssociationServer, bind a socket and start listening.bind(event, handler[, args])Bind a callable handler to an event.
close_request(request)Called to clean up an individual request.
fileno()Return socket file number.
finish_request(request, client_address)Finish one request by instantiating RequestHandlerClass.
Return a list of currently bound events.
get_handlers(event)Return handlers bound to a specific event.
Handle a connection request.
handle_error(request, client_address)Handle an error gracefully.
handle_request()Handle one request, possibly blocking.
handle_timeout()Called if no new request arrives within self.timeout.
process_request(request, client_address)Process a connection request
serve_forever([poll_interval])Handle one request at a time until shutdown.
server_activate()Called by constructor to activate the server.
Bind the socket and set the socket options.
Close the server.
Called by the serve_forever() loop
shutdown()Completely shutdown the server and close it's socket.
shutdown_request(request)Called to shutdown and close an individual request.
unbind(event, handler)Unbind a callable handler from an event.
verify_request(request, client_address)Verify the request.
Attributes
Return the server's running
Associationacceptor instancesaddress_familyallow_reuse_addresssocket_typeReturn the
ssl.SSLContext(if available).timeout- property active_associations: list[Association]#
Return the server’s running
Associationacceptor instances
- bind(event: NotificationEvent | InterventionEvent, handler: Callable, args: list[Any] | None = None) None[source]#
Bind a callable handler to an event.
- Parameters:
event (namedtuple) – The event to bind the function to.
handler (callable) – The function that will be called if the event occurs.
args (list, optional) – Optional extra arguments to be passed to the handler (default: no extra arguments passed to the handler).
- get_events() list[NotificationEvent | InterventionEvent][source]#
Return a list of currently bound events.
- get_handlers(event: NotificationEvent | InterventionEvent) list[tuple[Callable, list[Any] | None]] | tuple[Callable, list[Any] | None][source]#
Return handlers bound to a specific event.
- Parameters:
event (namedtuple) – The event bound to the handlers.
- Returns:
If the event is a notification event then returns a list of 2-tuples containing the callable functions bound to event and the arguments passed to the callable as
(callable, args). If the event is an intervention event then returns either a 2-tuple of (callable, args) if a handler is bound to the event or(None, None)if no handler has been bound.- Return type:
2-tuple of (callable, args), list of 2-tuple
- get_request() tuple[socket, tuple[str, int]][source]#
Handle a connection request.
If
ssl_contextis set then the client socket will be wrapped usingSSLContext.wrap_socket().- Returns:
client_socket (socket.socket) – The connection request.
address (2-tuple) – The client’s address as
(host, port).
- process_request(request: socket | tuple[bytes, socket], client_address: tuple[str, int] | str) None[source]#
Process a connection request
- server_bind() None[source]#
Bind the socket and set the socket options.
socket.SO_REUSEADDRis set to1socket.settimeout is used to set to
AE.network_timeoutunless the value isNonein which case it will be left unset.
- property ssl_context: SSLContext | None#
Return the
ssl.SSLContext(if available).- Parameters:
context (ssl.SSLContext or None) – If TLS is to be used then this should be the
ssl.SSLContextused to wrap the client sockets, otherwise ifNonethen no TLS will be used (default).
- unbind(event: NotificationEvent | InterventionEvent, handler: Callable) None[source]#
Unbind a callable handler from an event.
- Parameters:
event (3-tuple) – The event to unbind the function from.
handler (callable) – The function that will no longer be called if the event occurs.