Implementing SMPP Gateway (with sample app)
When you resell SMPP traffic you need to implement SMPP Gateway or SMPP Proxy.
Please note the SMPP Gateway sample program is available at the link.
Such application should start at least one SmppServer to be able to receive SMPP commands on a TCP port and several SmppClient instances to send message to other SMPP servers (SMSC, Provider).
When a customer sends SubmitSm command to your server, you need to send back a response SubmitSmResp with assigned MessageId. Later, when you forward this message to another server, you will receive another MessageId from SMSC.
This SMSC MessageId should also be replaced in DeliverSm ( Receipt) for the target client.
You might want to implement smart routing for incoming messages. F.i. when you are going to forward SMS message you can estimate which SmppClient connection accepts destination phone number and costs less.
When you need only forward SubmitSm messages I suggest following steps:
- Receive SubmitSm from the client.
- Save client's Sequence number to the database. Possible good idea to save entire PDU.
- Send SubmitSmResp to client with his Sequence number and MessageId generated on your server side.
- In another process/thread send this SubmitSm PDU to some SMPP provider.
- Change SubmitSm Sequence number to the next sequence number for the SmppClient that connected to that SMPP provider.
- Receive Provider's MessageId in SubmitSmResp
- Store Provider's MessageId and Sequence number to the same database table as for client's Sequence number.
These four values help later to find a corresponding client that should receive a delivery receipt from the provider:
- Client's sequence number
- Client's MessageId
- Provider's sequence number
- Provider's MessageId
When DeliverSm comes from the provider and contains "DeliveryReceipt", you should do the following steps:
- Get Provider's MessageId from delivery Receipt.
- Find client's MessageId and corresponding SMPP user.
- Replace Provider's MessageId in DeliverSm PDU with client's MessageId
- Send "DeliveryReceipt" to the SmppServerClient that belongs to SMPP user.
- If there is no active connection with the client, place DeliverSm PDU to the outgoing persistent queue (another database table) and send it when the client connects.
Example of forwarding message from one client to another is on the page "Message delivery from sender to recipient"