gosmpp

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2019 License: MIT Imports: 12 Imported by: 11

README

gosmpp

Golang Smpp (3.4) Client Library, porting from Java OpenSMPP Library.

This library is tested well with several SMSC simulators:

  • smpp-smsc-simulator: simulates a SMSC server – server which accepts SMS messages and handles its delivery to the mobile phone.
  • SMPPSim: a SMPP SMSC simulation tool, designed to help you test your SMPP based application. SMPPSim is free of charge and open source.

gosmpp has run well in production now:

  • My friend at traithivang.vn has used gosmpp as client to SMSC of Vietnamobile, a telecommunications company in Vietnam, without any problems for months.

Installation

go get -u github.com/linxGnu/gosmpp

Usage

Please refer to Communication Test Case for sample code. If you are familiar with OpenSMPP, you would know how to implement it easily.

Full example could be found: gist

Supported PDUs

  • bind_transmitter
  • bind_transmitter_resp
  • bind_receiver
  • bind_receiver_resp
  • bind_transceiver
  • bind_transceiver_resp
  • outbind
  • unbind
  • unbind_resp
  • submit_sm
  • submit_sm_resp
  • submit_sm_multi
  • submit_sm_multi_resp
  • data_sm
  • data_sm_resp
  • deliver_sm
  • deliver_sm_resp
  • query_sm
  • query_sm_resp
  • cancel_sm
  • cancel_sm_resp
  • replace_sm
  • replace_sm_resp
  • enquire_link
  • enquire_link_resp
  • alert_notification
  • generic_nack

Contributing

Please issue me for things gone wrong or:

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Documentation

Index

Constants

View Source
const (
	RECEIVER_THREAD_NAME = "Receiver"
	RECEIVE_CHAN_SIZE    = 10000
)
View Source
const (
	STATE_NOT_ALLOWED int32 = 0x00
	STATE_CLOSED      int32 = 0x01
	STATE_OPENED      int32 = 0x02
	STATE_TRANSMITTER int32 = 0x04
	STATE_RECEIVER    int32 = 0x08
	STATE_TRANSCEIVER int32 = 0x10
	STATE_ALWAYS      int32 = STATE_OPENED | STATE_TRANSMITTER | STATE_RECEIVER | STATE_TRANSCEIVER
	TYPE_ESME         int32 = 1
	TYPE_MC           int32 = 2
)
View Source
const (
	// CONN_SERVER              byte  = 2
	CONN_NONE                byte = 0
	CONN_CLIENT              byte = 1
	DFLT_IO_BUF_SIZE         int  = 2 * 1024
	DFLT_RECEIVE_BUFFER_SIZE int  = 4 * 1024
	DFLT_MAX_RECEIVE_SIZE    int  = 128 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func (*Connection) GetAddress

func (c *Connection) GetAddress() string

func (*Connection) GetReceiveTimeout

func (c *Connection) GetReceiveTimeout() int64

func (*Connection) GetSendTimeout

func (c *Connection) GetSendTimeout() int64

func (*Connection) SetAddress

func (c *Connection) SetAddress(addr string)

func (*Connection) SetDefault

func (c *Connection) SetDefault()

func (*Connection) SetReceiveTimeout

func (c *Connection) SetReceiveTimeout(t int64)

func (*Connection) SetSendTimeout

func (c *Connection) SetSendTimeout(t int64)

type IConnection

type IConnection interface {
	SetReceiveTimeout(t int64)
	GetReceiveTimeout() int64
	SetSendTimeout(t int64)
	GetSendTimeout() int64
	SetAddress(addr string)
	GetAddress() string
	Open() *Exception.Exception
	IsOpened() bool
	Close() *Exception.Exception
	Send(data *Utils.ByteBuffer) *Exception.Exception
	Receive() (*Utils.ByteBuffer, *Exception.Exception)
}

IConnection smpp connection interface

type IReceiver

type IReceiver interface {
	Receive()
	TryReceivePDU(IConnection, PDU.IPDU) (PDU.IPDU, *Exception.Exception)
}

type ReceivedPDUEvent

type ReceivedPDUEvent struct {
	Connection IConnection
	Pdu        PDU.IPDU
	Source     interface{}
	// contains filtered or unexported fields
}

func NewReceivedPDUEvent

func NewReceivedPDUEvent(source *receiverBase, con IConnection, pdu PDU.IPDU) *ReceivedPDUEvent

func (*ReceivedPDUEvent) GetConnection

func (c *ReceivedPDUEvent) GetConnection() IConnection

func (*ReceivedPDUEvent) GetPDU

func (c *ReceivedPDUEvent) GetPDU() PDU.IPDU

type Receiver

type Receiver struct {
	// contains filtered or unexported fields
}

func NewReceiver

func NewReceiver(listener ServerPDUEventListener) (r *Receiver)

func NewReceiverWithConnection

func NewReceiverWithConnection(listener ServerPDUEventListener, conn IConnection) (r *Receiver)

func NewReceiverWithTransmitterCon

func NewReceiverWithTransmitterCon(listener ServerPDUEventListener, trans *Transmitter, conn IConnection) (r *Receiver)

func (*Receiver) Receive added in v0.1.1

func (c *Receiver) Receive()

*

  • This method receives a PDU from connection and stores it into
  • <code>pduQueue</code>. It's called from the <code>ReceiverBase</code>'s
  • p<code>process</code> method which is called in loop from
  • <code>ProcessingThread</code>'s <code>run</code> method.
  • <p>
  • If an exception occurs during receiving, depending on type
  • of the exception this method either just reports the exception to
  • debug & event objects or stops processing to indicate
  • that it isn't able to process the exception. The function
  • <code>setTermException</code> is then called with the caught exception. *
  • @see ReceiverBase#run()

func (*Receiver) ReceivePDUFromConnection added in v0.1.1

func (c *Receiver) ReceivePDUFromConnection(conn IConnection, unprocessed *Utils.Unprocessed) (PDU.IPDU, *Exception.Exception)

func (*Receiver) ReceiveSyncWTimeout

func (c *Receiver) ReceiveSyncWTimeout(timeout int64) (PDU.IPDU, *Exception.Exception)

*

  • This method receives a PDU or returns PDU received on background,
  • if there is any. It tries to receive a PDU for the specified timeout.
  • If the receiver is asynchronous, then no attempt to receive a PDU
  • and <code>null</code> is returned.
  • The function calls are nested as follows:<br>
  • <ul>
  • <li>No background receiver thread<br><code>
  • Receiver.receive(long)<br>
  • ReceiverBase.tryReceivePDUWithTimeout(Connection,PDU,long)<br>
  • Receiver.tryReceivePDU(Connection,PDU)<br>
  • ReceiverBase.receivePDUFromConnection<br>
  • Connection.receive()</code>
  • <li>Has background receiver thread<br><code>
  • Receiver.receive(long)<br>
  • ReceiverBase.tryReceivePDUWithTimeout(Connection,PDU,long)<br>
  • Receiver.tryReceivePDU(Connection,PDU)<br>
  • Queue.dequeue(PDU)</code><br>
  • and the ReceiverBase.run() function which actually receives the
  • PDUs and stores them to a queue looks as follows:<br><code>
  • ReceiverBase.run()<br>
  • Receiver.receiveAsync()<br>
  • ReceiverBase.receivePDUFromConnection<br>
  • Connection.receive()</code> *
  • @param timeout for how long is tried to receive a PDU
  • @return the received PDU or null if none received for the spec. timeout *
  • @exception IOException exception during communication
  • @exception PDUException incorrect format of PDU
  • @exception TimeoutException rest of PDU not received for too long time
  • @exception UnknownCommandIdException PDU with unknown id was received
  • @see ReceiverBase#tryReceivePDUWithTimeout(Connection,PDU,long)

func (*Receiver) ReceiveSyncWithExpectedPDU

func (c *Receiver) ReceiveSyncWithExpectedPDU(pdu PDU.IPDU) (PDU.IPDU, *Exception.Exception)

*

  • Called from session to receive a response for previously sent request. *
  • @param expectedPDU the template for expected PDU; the PDU returned
  • must have the same sequence number
  • @return the received PDU or null if none
  • @see ReceiverBase#tryReceivePDUWithTimeout(Connection,PDU,long)

func (Receiver) SetReceiveTimeout added in v0.1.2

func (c Receiver) SetReceiveTimeout(timeout int64)

func (*Receiver) Start

func (c *Receiver) Start()

Start will reset unprocessed data and start receiving on the background.

func (*Receiver) Stop

func (c *Receiver) Stop()

Stop receiver.

func (*Receiver) StopByException

func (c *Receiver) StopByException(e *Exception.Exception)

StopByException stops receiver and print err log.

func (*Receiver) TryReceivePDU

func (c *Receiver) TryReceivePDU(conn IConnection, expected PDU.IPDU) (pduResult PDU.IPDU, expc *Exception.Exception)

type ServerPDUEvent

type ServerPDUEvent struct {
	ReceivedPDUEvent
}

func NewServerPDUEvent

func NewServerPDUEvent(source *Receiver, con IConnection, pdu PDU.IPDU) *ServerPDUEvent

func (*ServerPDUEvent) GetReceiver

func (c *ServerPDUEvent) GetReceiver() *Receiver

type ServerPDUEventListener

type ServerPDUEventListener interface {
	HandleEvent(event *ServerPDUEvent) *Exception.Exception
	HandleException(*Exception.Exception)
}

type Session

type Session struct {
	// contains filtered or unexported fields
}

func NewSessionWithConnection

func NewSessionWithConnection(conn IConnection) *Session

func (*Session) AlertNotification

func (c *Session) AlertNotification(req *PDU.AlertNotification) (err *Exception.Exception)

func (*Session) Bind

func (*Session) BindWithListener

func (c *Session) BindWithListener(req PDU.IBindRequest, pduListener ServerPDUEventListener) (bindResp PDU.IResponse, err *Exception.Exception)

func (*Session) Cancel

func (c *Session) Cancel(req *PDU.CancelSM) (resp *PDU.CancelSMResp, err *Exception.Exception)

func (*Session) CheckPDUState

func (c *Session) CheckPDUState(pdu PDU.IPDU) *Exception.Exception

func (*Session) CheckState

func (c *Session) CheckState(requestedState int32) *Exception.Exception

func (*Session) Close

func (c *Session) Close() *Exception.Exception

func (*Session) Data

func (c *Session) Data(req *PDU.DataSM) (resp *PDU.DataSMResp, err *Exception.Exception)

func (*Session) Deliver

func (c *Session) Deliver(req *PDU.DeliverSM) (resp *PDU.DeliverSMResp, err *Exception.Exception)

func (*Session) DisableStateChecking

func (c *Session) DisableStateChecking()
func (c *Session) DoEnquireLink() (resp *PDU.EnquireLinkResp, err *Exception.Exception)

func (*Session) EnableStateChecking

func (c *Session) EnableStateChecking()
func (c *Session) EnquireLink(req *PDU.EnquireLink) (resp *PDU.EnquireLinkResp, err *Exception.Exception)

func (*Session) GenericNack

func (c *Session) GenericNack(resp *PDU.GenericNack) *Exception.Exception

func (*Session) GenericNackWithCmStatusSeqNum

func (c *Session) GenericNackWithCmStatusSeqNum(commandStatus, sequenceNumber int32) *Exception.Exception

func (*Session) GetConnection

func (c *Session) GetConnection() IConnection

func (*Session) GetReceiver

func (c *Session) GetReceiver() *Receiver

func (*Session) GetState

func (c *Session) GetState() int32

func (*Session) GetTransmitter

func (c *Session) GetTransmitter() *Transmitter

func (*Session) GetType

func (c *Session) GetType() int32

func (*Session) IsBound

func (c *Session) IsBound() bool

func (*Session) IsOpened

func (c *Session) IsOpened() bool

func (*Session) IsPDUAllowed

func (c *Session) IsPDUAllowed(pdu PDU.IPDU) bool

func (*Session) IsStateAllowed

func (c *Session) IsStateAllowed(requestedState int32) bool

func (*Session) Open

func (c *Session) Open() *Exception.Exception

func (*Session) Query

func (c *Session) Query(req *PDU.QuerySM) (resp *PDU.QuerySMResp, err *Exception.Exception)

func (*Session) Receive

func (c *Session) Receive() (pdu PDU.IPDU, err *Exception.Exception)

func (*Session) ReceiveWTimeout

func (c *Session) ReceiveWTimeout(timeout int64) (pdu PDU.IPDU, err *Exception.Exception)

func (*Session) Replace

func (c *Session) Replace(req *PDU.ReplaceSM) (resp *PDU.ReplaceSMResp, err *Exception.Exception)

func (*Session) Respond

func (c *Session) Respond(resp PDU.IResponse) (err *Exception.Exception)

func (*Session) Send

func (c *Session) Send(req PDU.IRequest) (resp PDU.IResponse, err *Exception.Exception)

func (*Session) SendAsync added in v0.1.1

func (c *Session) SendAsync(req PDU.IRequest, isAsync bool) (resp PDU.IResponse, err *Exception.Exception)

func (*Session) SetType

func (c *Session) SetType(t int32)

func (*Session) Submit

func (c *Session) Submit(req *PDU.SubmitSM) (resp *PDU.SubmitSMResp, err *Exception.Exception)

func (*Session) SubmitMulti

func (c *Session) SubmitMulti(req *PDU.SubmitMultiSM) (resp *PDU.SubmitMultiSMResp, err *Exception.Exception)

func (*Session) Unbind

func (c *Session) Unbind() (unbindResp *PDU.UnbindResp, err *Exception.Exception)

type SocketFactory

type SocketFactory struct {
}

func (SocketFactory) CreateTCP

func (c SocketFactory) CreateTCP(address string, port int) (*net.TCPConn, error)

type TCPIPConnection

type TCPIPConnection struct {
	Connection
	// contains filtered or unexported fields
}

func NewTCPIPConnection

func NewTCPIPConnection() *TCPIPConnection

NewTCPIPConnection new tcp ip connection

func NewTCPIPConnectionWithAddrPort

func NewTCPIPConnectionWithAddrPort(addr string, port int) (*TCPIPConnection, error)

NewTCPIPConnectionWithAddrPort new tcp/ip connection with addr and port

func NewTCPIPConnectionWithSocket

func NewTCPIPConnectionWithSocket(soc *net.TCPConn) (*TCPIPConnection, error)

NewTCPIPConnectionWithSocket new tcp/ip connection with preallocated socket. Useful for tls enabled connection.

func (*TCPIPConnection) Close

func (c *TCPIPConnection) Close() *Exception.Exception

Close connection

func (*TCPIPConnection) IsOpened

func (c *TCPIPConnection) IsOpened() bool

IsOpened check if connection is opened

func (*TCPIPConnection) Open

func (c *TCPIPConnection) Open() *Exception.Exception

Open connection

func (*TCPIPConnection) Receive

func (c *TCPIPConnection) Receive() (result *Utils.ByteBuffer, err *Exception.Exception)

Receive message from connection in form of buffer

func (*TCPIPConnection) Send

func (c *TCPIPConnection) Send(data *Utils.ByteBuffer) (err *Exception.Exception)

Send buffered data

func (*TCPIPConnection) SetIOBufferSize

func (c *TCPIPConnection) SetIOBufferSize(size int)

SetIOBufferSize set io buffer size

func (*TCPIPConnection) SetMaxReceiveSize

func (c *TCPIPConnection) SetMaxReceiveSize(size int)

SetMaxReceiveSize set max length of message allowed to receive over socket

func (*TCPIPConnection) SetReceiveBufferSize

func (c *TCPIPConnection) SetReceiveBufferSize(size int)

SetReceiveBufferSize set buffer size for receiving message over socket

type Transmitter

type Transmitter struct {
	// contains filtered or unexported fields
}

func NewTransmitter

func NewTransmitter() *Transmitter

func NewTransmitterWithConnection

func NewTransmitterWithConnection(con IConnection) *Transmitter

func (*Transmitter) Send

func (c *Transmitter) Send(pdu PDU.IPDU) *Exception.Exception

type UnbindServerPDUEventListener

type UnbindServerPDUEventListener struct {
	// contains filtered or unexported fields
}

func NewUnbindServerPDUEventListener

func NewUnbindServerPDUEventListener(sess *Session, origListener ServerPDUEventListener, unbindReq *PDU.Unbind) *UnbindServerPDUEventListener

func (*UnbindServerPDUEventListener) GetUnbindResp

func (c *UnbindServerPDUEventListener) GetUnbindResp() *PDU.UnbindResp

func (*UnbindServerPDUEventListener) HandleEvent

func (*UnbindServerPDUEventListener) HandleException added in v0.1.3

func (c *UnbindServerPDUEventListener) HandleException(err *Exception.Exception)

func (*UnbindServerPDUEventListener) StartWait

func (c *UnbindServerPDUEventListener) StartWait(miliSecond int64)

Directories

Path Synopsis
PDU
TLV

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL