SMPP binds and enquire_link: keeping an SMS connection alive on a VPS

WhatsApp & APIs·· 18 views· 4 min read

The short answer (for those with a VPS and an SMPP account): an SMPP session starts with a TCP connection to the host and port your provider gave you, followed by a bind with your system_id and password. If the bind_resp comes back with status 0, you are in. From then on, whenever the line is quiet, each side sends an enquire_link now and then (“are you there?”) and the other answers with enquire_link_resp. Without it, a firewall or NAT along the way can silently forget the connection, and your program keeps believing it is connected when it is not.

The session commands

Command What it does
bind_transmitter Sends only. Delivery reports and replies do not arrive on this connection.
bind_receiver Receives only: the deliver_sm packets with replies and receipts.
bind_transceiver Sends and receives over one connection. The simplest option when the provider allows it.
enquire_link / enquire_link_resp “Are you there?” / “Yes”. Keeps the connection alive and exposes a dead one.
unbind / unbind_resp A goodbye before closing. Without it, the provider may keep counting the old session as open.
generic_nack The other side could not understand a packet (wrong length, unknown command). Nearly always a client bug.

Building a connection that holds

1 Check that the VPS can reach the provider. The outgoing port must be open in the VPS firewall and the provider must have allowed the VPS IP. Test with the host and port you were given: nc -vz SMPP_HOST SMPP_PORT If the test hangs until it gives up, it is a firewall or an IP not allowed; if it is refused straight away, the port is wrong. See ports and firewall on a VPS.
2 Bind with credentials read from the environment, not written into the code: system_id, password and, if the provider asks for it, system_type. Common errors in bind_resp: invalid password, bind failed, or “already bound” (the old session still counts, or two copies of the client are running).
3 Send an enquire_link when the line has been quiet for a while. Use the interval your provider recommends, and keep it shorter than the time firewalls and NAT along the way take to forget an idle connection. And always answer the enquire_link packets the provider sends you: not answering is a classic reason for the provider to drop the session.
4 If an enquire_link gets no answer within your timeout, or the connection closes, treat the session as dead: close it, wait, and reconnect with growing pauses between attempts, so you do not hammer the provider. Sends that had no submit_sm_resp yet go back into the queue; they are neither lost nor counted as sent.
5 Respect the window and the rate. The window is how many packets you may have sent without an answer at once, and the provider sets it. Above it, or above the agreed rate, errors such as ESME_RTHROTTLED or ESME_RMSGQFUL come back: slow down and retry later.
6 Run the client as a systemd service, with automatic restart and logs in the journal (running your program as a service). On stop, the program should catch the stop signal and send an unbind before closing.
Run a single copy of the client per account, unless the provider allowed several binds. Two copies (one forgotten in a terminal session, plus the service) cause “already bound” errors or split receipts between two processes, and one of them throws them away.
Log each packet’s command, sequence_number and status, never the password or the text of messages carrying codes. The sequence_number lets you match each _resp to the request that caused it. Where to find the logs: logs on a Linux VPS.

Your VPS cannot connect to the SMS provider? Send us the host, the port and the result of the nc test, and we help you find where the block is (on an unmanaged VPS, the firewall is yours to manage).

Open a support ticket

SEE ALSO

SMPP or an HTTP SMS API: what each one is and which your application needs

SMS delivery reports (DLR): how your application knows whether a message arrived

How to run your own program as a systemd service that starts at boot

Ports and firewall on a VPS: why your app is not reachable

Where are the logs on a Linux VPS: journalctl and /var/log

Environment variables and secrets for your application

RECOMMENDED PRODUCT

VPS server with root access

Resources of your own, the OS you choose, reinstall whenever you like. from $8.39/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.