GithubHelp home page GithubHelp logo

Using smpp34 as a server about smpp34 HOT 2 CLOSED

jaroszan avatar jaroszan commented on June 20, 2024
Using smpp34 as a server

from smpp34.

Comments (2)

CodeMonkeyKevin avatar CodeMonkeyKevin commented on June 20, 2024

Server mode is not created as the this lib is just for parsing/creating SMPP3.4 PDUs. A lot of SMPP server have business logic tied to it so you can use this lib to create our own server.

You can use something like this to handle incoming connections.

func startServer {
    ln, err := net.Listen("tcp", ":8080")

    if err != nil {
        // handle error
    }

    for {
        conn, err := ln.Accept()
        if err != nil {
            // handle error
            continue
        }
        go handleConnection(conn)
    }
}

func handleConnection(conn net.Conn) {
        // setup struct
        trx := &Smpp{}
        trx.conn = conn

    // start reading PDUs
    for {
        pdu, err := trx.Read() // This is blocking
        if err != nil {
            fmt.Println("Read Err:", err)
            fmt.Println(trx.Err)
            break
        }

        // Transceiver auto handles EnquireLinks
        switch pdu.GetHeader().Id {
        case smpp.SUBMIT_SM_RESP:
            // message_id should match this with seq message
            fmt.Println("MSG ID:", pdu.GetField("message_id").Value())
        case smpp.DELIVER_SM:
            // received Deliver Sm
            for _, v := range pdu.MandatoryFieldsList() {
                f := pdu.GetField(v)
                fmt.Println(v, ":", f)
            }

            // Respond back to Deliver SM with Deliver SM Resp
            err := trx.DeliverSmResp(pdu.GetHeader().Sequence, smpp.ESME_ROK)

            if err != nil {
                fmt.Println("DeliverSmResp err:", err)
            }

            // trx.Unbind()
        case smpp.UNBIND:
            // Received Unbind connection is already closed. Stop the read loop
            fmt.Println("Unbound")
            return
        default:
            fmt.Println("PDU:", pdu.GetHeader())
        }
    }
}

from smpp34.

jaroszan avatar jaroszan commented on June 20, 2024

Thanks a lot!

from smpp34.

Related Issues (13)

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.