SMPP 3.4 Library
smpp is library contains implementation of SMPP 3.4 protocol.
It allows easier creation of SMPP clients and servers by providing utilities for PDU and session handling.
Project Status
Although usable, project is still to be considered as WORK IN PROGRESS until it reaches it's first official version. Util then breaking API to fix possible design flaws is possible.
Project goals
- Provide API for manipulating and observing PDU data.
- Provide API for SMPP session handling.
- Provide reference SMPP SMSC Server implementation.
- Enforce SMPP specification integrity (to the most useful degree).
Feature description
Installation
You can use go get:
go get -u github.com/dolnikov/smpp
Usage
In order to do any kind of interaction you first need to create an SMPP Session. Session is the main carrier of the protocol and enforcer of the specification rules.
Naked session can be created with:
// You must provide already established connection and configuration struct.
sess := smpp.NewSession(conn, conf)
But it's much more convenient to use helpers that would do the binding with the remote SMSC and return you session prepared for sending:
// Bind with remote server by providing config structs.
sess, err := smpp.BindTRx(sessConf, bindConf)
And once you have the session it can be used for sending PDUs to the binded peer.
sm := smpp.SubmitSm{
SourceAddr: "11111111",
DestinationAddr: "22222222",
ShortMessage: "Hello from SMPP!",
}
// Session can then be used for sending PDUs.
resp, err := sess.Send(p)
Session that is no longer used must be closed:
sess.Close()
If you want to handle incoming requests to the session specify SMPPHandler in session configuration when creating new session similarly to HTTPHandler from net/http package:
conf := smpp.SessionConf{
Handler: smpp.HandlerFunc(func(ctx *smpp.Context) {
switch ctx.CommandID() {
case pdu.UnbindID:
ubd, err := ctx.Unbind()
if err != nil {
t.Errorf(err.Error())
}
resp := ubd.Response()
if err := ctx.Respond(resp, pdu.StatusOK); err != nil {
t.Errorf(err.Error())
}
}
}),
}
Detailed examples for SMPP client and server can be found in the examples dir.