-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using smpp34 as a server #10
Comments
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())
}
}
} |
Thanks a lot! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As mentioned in subj.
It seems that currently smpp34 can connect to external entity, but cannot operate in server mode (creating RX/TX/TRX assumes that we connect and act as a client, not a server), eg:
From transceiver.go (receiver and transmitter example are identical):
Is there a workaroung/quick fix to be able to listen for incoming connections and use trx/tx/rx methods?
The text was updated successfully, but these errors were encountered: