pynetdicom.transport.AssociationSocket

class pynetdicom.transport.AssociationSocket(assoc: Association, client_socket: Optional[socket.socket] = None, address: Tuple[str, int] = ('', 0))[source]

A wrapper for a socket object.

New in version 1.2.

Provides an interface for socket that is integrated nicely with an Association instance and the state machine.

select_timeout

The timeout (in seconds) that select.select() calls in ready() will block for (default 0.5). A value of 0 specifies a poll and never blocks. A value of None blocks until a connection is ready.

Type

float or None

socket

The wrapped socket, will be None if close() is called.

Type

socket.socket or None

__init__(assoc: Association, client_socket: Optional[socket.socket] = None, address: Tuple[str, int] = ('', 0)) None[source]

Create a new AssociationSocket.

Parameters
  • assoc (association.Association) – The Association instance that will be using the socket to communicate.

  • client_socket (socket.socket, optional) – The socket.socket to wrap, if not supplied then a new socket will be created instead.

  • address (2-tuple, optional) – If client_socket is None then this is the (host, port) to bind the newly created socket to, which by default will be ("", 0).

Methods

__init__(assoc[, client_socket, address])

Create a new AssociationSocket.

close()

Close the connection to the peer and shutdown the socket.

connect(primitive)

Try and connect to a remote using connection details from primitive.

get_local_addr([host])

Return an address for the local computer as str.

recv(nr_bytes)

Read nr_bytes from the socket.

send(bytestream)

Try and send the data in bytestream to the remote.

Attributes

assoc

Return the parent Association instance.

event_queue

Return the Association's service event queue.

provider_queue

Return the Association's service provider queue.

ready

Return True if there is data available to be read.

tls_args

Get or set the TLS context and hostname.

property assoc: Association

Return the parent Association instance.

close() None[source]

Close the connection to the peer and shutdown the socket.

Sets AssociationSocket.socket to None once complete.

Events Emitted

  • Evt17: Transport connection closed

connect(primitive: pynetdicom.transport.T_CONNECT) None[source]

Try and connect to a remote using connection details from primitive.

Changed in version 2.0: Changed to take a T_CONNECT primitive rather than an address tuple.

Parameters

primitive (pynetdicom.transport.T_CONNECT) – The TRANSPORT CONNECT primitive to use when connecting to a peer.

property event_queue: queue.Queue[str]

Return the Association’s service event queue.

get_local_addr(host: Tuple[str, int] = ('10.255.255.255', 1)) str[source]

Return an address for the local computer as str.

Parameters

host (Tuple[str, int]) – The host’s (addr: str, port: int) when trying to determine the local address.

property provider_queue: _QueueType

Return the Association’s service provider queue.

property ready: bool

Return True if there is data available to be read.

Events Emitted

  • None

  • Evt17: Transport connection closed

Returns

True if the socket has data ready to be read, False otherwise.

Return type

bool

recv(nr_bytes: int) bytearray[source]

Read nr_bytes from the socket.

Events Emitted

  • None

Parameters

nr_bytes (int) – The number of bytes to attempt to read from the socket.

Returns

The data read from the socket.

Return type

bytearray

send(bytestream: bytes) None[source]

Try and send the data in bytestream to the remote.

Events Emitted

  • None

  • Evt17: Transport connected closed.

Parameters

bytestream (bytes) – The data to send to the remote.

property tls_args: Optional[Tuple[ssl.SSLContext, str]]

Get or set the TLS context and hostname.

Parameters

tls_args (Tuple[ssl.SSLContext, str] or None) – If the socket should be wrapped by TLS then this is (context, hostname), where context is a ssl.SSLContext that will be used to wrap the socket and hostname is the value to use for the server_hostname keyword argument for SSLContext.wrap_socket().

Returns

Return type

Optional[Tuple[ssl.SSLContext, str]]