This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
forked from CodeMonkeyKevin/smpp34
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trx_example.go
68 lines (58 loc) · 1.38 KB
/
trx_example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
smpp "github.com/t0pep0/smpp34"
)
func main() {
// connect and bind
trx, err := smpp.NewTransceiver(
"smpp",
2775,
5,
smpp.Params{
"system_type": "CMT",
"system_id": "t0pep0",
"password": "pass",
},
)
if err != nil {
fmt.Println("Connection Err:", err)
return
}
// Send SubmitSm
seq, err := trx.SubmitSm("test", "test", "Hello! Привет!", &smpp.Params{smpp.REGISTERED_DELIVERY: 1})
// Pdu gen errors
if err != nil {
fmt.Println("SubmitSm err:", err)
}
// Should save this to match with message_id
fmt.Println("seq:", seq)
// start reading PDUs
for {
pdu, err := trx.Read() // This is blocking
if err != nil {
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:", string(pdu.GetField("message_id").Value().([]uint8)))
case smpp.DELIVER_SM:
// received Deliver Sm
// Print all fields
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)
}
default:
fmt.Println("PDU ID:", pdu.GetHeader().Id)
}
}
fmt.Println("ending...")
}