Giter Site home page Giter Site logo

go-smpp's Introduction

go-smpp

A complete implementation of SMPP v5 protocol, written in golang.

Key features

  • Message encoding auto-detection
  • Multipart SMS automatic splitting and concatenating

Supported encodings:

  • GSM 7Bit
  • ASCII
  • Latin-1
  • Cyrillic
  • Hebrew
  • Shift-JIS
  • ISO-2022-JP
  • EUC-JP
  • EUC-KR
  • UCS-2

Caveats

Command line tools

  1. smpp-receiver
    SMPP Simple Receiver tool

  2. smpp-repl
    SMPP Simple Test tool

Example

  1. Connect to the Remote (SMPP server)

    parent, err := net.Dial("tcp", "m2m-device:2775")
    if err != nil {
        panic(err)
    }
    conn = smpp.NewConn(context.Background(), parent)
    conn.WriteTimeout = n * time.Second // set write timeout (optional, default 15 minutes)
    conn.ReadTimeout =  n * time.Second // set read timeout  (optional, default 15 minutes)
    go conn.Watch()                     // start watchdog
  2. Handshake

    resp, err := conn.Submit(context.Background(), &pdu.BindTransmitter{
        SystemID:   "your system id",
        Password:   "your password",
        SystemType: "your system type",
        Version:    pdu.SMPPVersion50,
    })
    if err != nil {
        panic(err)
    }
    r := resp.(*pdu.BindTransmitterResp)
    if r.Header.CommandStatus == 0 {
        // start keep-alive
        go conn.EnquireLink(time.Minute, time.Minute)
    }
  3. Send Message

    packet := &pdu.SubmitSM{
        SourceAddr: pdu.Address{TON: 1, NPI: 1, No: "00919821"},
        DestAddr:   pdu.Address{TON: 1, NPI: 1, No: "99919821"},
    }
    err := packet.Message.Compose("Hello World!")
    if err != nil {
        panic(err)
    }
    resp, err := conn.Submit(context.Background(), packet)
    if err != nil {
        panic(err)
    }
    resp // submit_sm_resp returns
  4. Event loop for receiving messages

    for {
        packet := <-conn.PDU()
        // reply a responsable packet
        if p, ok := packet.(pdu.Responsable); ok {
            err := conn.Send(p.Resp())
            if err != nil {
                fmt.Println(err)
            }
        }
    }

LICENSE

This piece of software is released under the MIT license.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

go-smpp's People

Contributors

septs avatar jamesits avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.