pynetdicom.transport.AssociationServer¶
-
class
pynetdicom.transport.
AssociationServer
(ae, address, ae_title, contexts, ssl_context=None, evt_handlers=None, request_handler=None)[source]¶ An Association server implementation.
New in version 1.2.
Changed in version 1.5: Added request_handler keyword parameter.
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 of0
specifies a poll and never blocks. A value ofNone
blocks until a connection is ready.-
ae
¶ The parent AE that is running the server.
- Type
-
server_address
¶ The
(host, port)
that the server is running on.- Type
2-tuple
-
ssl_context
¶ The
ssl.SSLContext
used to wrap client sockets, orNone
if no TLS is required (default).- Type
-
__init__
(ae, address, ae_title, contexts, ssl_context=None, evt_handlers=None, request_handler=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 (2-tuple) – The
(host, port)
that the server should run on.ae_title (bytes) – 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.SSLContext
used to wrap the client sockets, otherwise ifNone
then 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.
service_actions
()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
Association
acceptor instancesaddress_family
allow_reuse_address
socket_type
Return the
ssl.SSLContext
(if available).timeout
-
property
active_associations
¶ Return the server’s running
Association
acceptor instances
-
bind
(event, handler, args=None)[source]¶ Bind a callable handler to an event.
New in version 1.3.
Changed in version 1.5: Added args keyword parameter.
- 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_handlers
(event)[source]¶ Return handlers bound to a specific event.
New in version 1.3.
Changed in version 1.5: Returns a 2-tuple of (callable, args) or list of 2-tuple.
- 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
()[source]¶ Handle a connection request.
If
ssl_context
is 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)
.
-
server_bind
()[source]¶ Bind the socket and set the socket options.
socket.SO_REUSEADDR
is set to1
socket.SO_RCVTIMEO
is set toAE.network_timeout
unless the value isNone
in which case it will be left unset.
-
property
ssl_context
¶ Return the
ssl.SSLContext
(if available).
-