Client¶
-
class
naz.client.
Client
(smsc_host, smsc_port, system_id, password, broker, system_type='', addr_ton=0, addr_npi=0, address_range='', interface_version=52, client_id=None, enquire_link_interval=55.0, logger=None, rate_limiter=None, hook=None, sequence_generator=None, throttle_handler=None, correlation_handler=None, drain_duration=8.0, socket_timeout=30.0, custom_codecs=None)[source]¶ Bases:
object
The SMPP client that will interact with SMSC/server.
Example declaration:
import os import asyncio import naz broker = naz.broker.SimpleBroker(maxsize=1000) client = naz.Client( smsc_host="127.0.0.1", smsc_port=2775, system_id="smppclient1", password=os.getenv("password", "password"), broker=broker, ) # 1. connect to the SMSC host # 2. bind to the SMSC host # 3. send any queued messages to SMSC # 4. read any data from SMSC # 5. continually check the state of the SMSC tasks = asyncio.gather( client.connect(), client.tranceiver_bind(), client.dequeue_messages(), client.receive_data(), client.enquire_link(), ) loop = asyncio.get_event_loop() loop.run_until_complete(tasks)
-
__init__
(smsc_host, smsc_port, system_id, password, broker, system_type='', addr_ton=0, addr_npi=0, address_range='', interface_version=52, client_id=None, enquire_link_interval=55.0, logger=None, rate_limiter=None, hook=None, sequence_generator=None, throttle_handler=None, correlation_handler=None, drain_duration=8.0, socket_timeout=30.0, custom_codecs=None)[source]¶ - Parameters
smsc_host (
str
) – the IP address(or domain name) of the SMSC gateway/serversmsc_port (
int
) – the port at which SMSC is listening onsystem_id (
str
) – Identifies the ESME system requesting to bind as a transceiver with the SMSC.password (
str
) – The password to be used by the SMSC to authenticate the ESME requesting to bind.broker (
BaseBroker
) – python class instance implementing some queueing mechanism. messages to be sent to SMSC are queued using the said mechanism before been sentclient_id (
Union
[None
,str
]) – a unique string identifying a naz client class instancesystem_type (
str
) – Identifies the type of ESME system requesting to bind with the SMSC.addr_ton (
int
) – Type of Number of the ESME address.addr_npi (
int
) – Numbering Plan Indicator (NPI) for ESME address(es) served via this SMPP transceiver sessionaddress_range (
str
) – A single ESME address or a range of ESME addresses served via this SMPP transceiver session.interface_version (
int
) – Indicates the version of the SMPP protocol supported by the ESME.enquire_link_interval (
float
) – time in seconds to wait before sending an enquire_link request to SMSC to check on its statuslogger (
Union
[None
,Logger
]) – python logger instance to be used for loggingrate_limiter (
Union
[None
,BaseRateLimiter
]) – python class instance implementing rate limitationhook (
Union
[None
,BaseHook
]) – python class instance implemeting functionality/hooks to be called by naz just before sending request to SMSC and just after getting response from SMSCsequence_generator (
Union
[None
,BaseSequenceGenerator
]) – python class instance used to generate sequence_numbersthrottle_handler (
Union
[None
,BaseThrottleHandler
]) – python class instance implementing functionality of what todo when naz starts getting throttled responses from SMSCcorrelation_handler (
Union
[None
,BaseCorrelater
]) – A python class instance that naz uses to store relations between SMPP sequence numbers and user applications’ log_id’s and/or hook_metadata.drain_duration (
float
) – duration in seconds that naz will wait for after receiving a termination signal.socket_timeout (
float
) – duration that naz will wait, for socket/connection related activities with SMSC, before timing outcustom_codecs (
Union
[None
,Dict
[str
,CodecInfo
]]) – a dictionary of encodings and their corresponding codecs.CodecInfo that you would like to register.
- Raises
NazClientError – raised if there’s an error instantiating a naz Client.
- Return type
None
-
async
command_handlers
(pdu, body_data, smpp_command, command_status_value, sequence_number, log_id, hook_metadata)[source]¶ This routes the various different SMPP PDU to their respective handlers.
- Parameters
pdu (
bytes
) – the full PDU as received from SMSCbody_data (
bytes
) – PDU body as received from SMSCsmpp_command (
str
) – type of PDU been received. eg bind_transceiver_respcommand_status_value (
int
) – the response code from SMSC for a specific PDUsequence_number (
int
) – SMPP sequence_numberlog_id (
str
) – a unique identify of this requesthook_metadata (
str
) – additional metadata that you would like to be passed on to hooks
- Return type
None
-
async
deliver_sm_resp
(sequence_number)[source]¶ send a DELIVER_SM_RESP pdu to SMSC.
- Parameters
sequence_number (
int
) – SMPP sequence_number- Return type
None
-
async
dequeue_messages
(TESTING=False)[source]¶ In a loop; dequeues items from the
broker
and sends them to SMSC.- Parameters
TESTING (
bool
) – indicates whether this method is been called while running tests.- Return type
Union
[Message
,Dict
[Any
,Any
]]
-
async
enquire_link
(TESTING=False)[source]¶ send an ENQUIRE_LINK pdu to SMSC.
- Parameters
TESTING (
bool
) – indicates whether this method is been called while running tests.- Return type
Union
[None
,bytes
]
-
async
enquire_link_resp
(sequence_number)[source]¶ send an ENQUIRE_LINK_RESP pdu to SMSC.
- Parameters
sequence_number (
int
) – SMPP sequence_number- Return type
None
-
async
re_establish_conn_bind
(smpp_command, log_id, TESTING=False)[source]¶ Called if connection is lost. It reconnects & rebinds to SMSC.
- Parameters
TESTING (
bool
) – indicates whether this method is been called while running tests.- Return type
None
-
async
receive_data
(TESTING=False)[source]¶ In a loop; read bytes from the network connected to SMSC and hand them over to the
_parse_response_pdu
method for parsing.- Parameters
TESTING (
bool
) – indicates whether this method is been called while running tests.- Return type
Union
[None
,bytes
]
-
async
send_data
(smpp_command, msg, log_id, hook_metadata='')[source]¶ Sends PDU’s to SMSC over a network connection. This method does not block; it buffers the data and arranges for it to be sent out asynchronously. It also accts as a flow control method that interacts with the IO write buffer.
- Parameters
smpp_command (
str
) – type of PDU been sent. eg bind_transceivermsg (
bytes
) – PDU to be sent to SMSC over the network connection.log_id (
str
) – a unique identify of this requesthook_metadata (
str
) – additional metadata that you would like to be passed on to hooks
- Return type
None
-
async
send_message
(proto_msg)[source]¶ Sends a message/SUBMIT_SM to SMSC. That message will get enqueued to
broker
and later on sent to SMSC.- Parameters
proto_msg (
SubmitSM
) – the message to send to SMSC. Has to be a class instance ofnaz.protocol.SubmitSM
Usage:
import naz broker = naz.broker.SimpleBroker(maxsize=1000) client = naz.Client( smsc_host="127.0.0.1", smsc_port=2775, system_id="smppclient1", password=os.getenv("password", "password"), broker=broker, ) msg = naz.protocol.SubmitSM( short_message="hello world", source_addr="255700111222", destination_addr="255799000888", log_id="some-id", ) await client.send_message(msg)
- Return type
None
-