Implement a basic smpp client
This commit is contained in:
44
main.go
44
main.go
@@ -4,9 +4,9 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"log"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"smpptester/client"
|
||||
"smpptester/pdu"
|
||||
)
|
||||
|
||||
@@ -166,47 +166,19 @@ func main() {
|
||||
buf := pdu.ByteBufferPool.Get(submit.Size())
|
||||
defer pdu.ByteBufferPool.Put(buf)
|
||||
submit.Encode(buf)
|
||||
log.Println(buf.Bytes())
|
||||
log.Println(createSubmitSMPDU())
|
||||
// log.Println(pdu.Encode())
|
||||
// serviceType := "CMT"
|
||||
// sourceAddrTON := byte(0x01)
|
||||
// sourceAddrNPI := byte(0x01)
|
||||
// sourceAddr := "12345"
|
||||
// destAddrTON := byte(0x01)
|
||||
// destAddrNPI := byte(0x01)
|
||||
// destinationAddr := "67890"
|
||||
// esmClass := byte(0x00)
|
||||
// protocolID := byte(0x00)
|
||||
// priorityFlag := byte(0x00)
|
||||
// scheduleDeliveryTime := ""
|
||||
// validityPeriod := ""
|
||||
// registeredDelivery := byte(0x01)
|
||||
// replaceIfPresentFlag := byte(0x00)
|
||||
// dataCoding := byte(0x01)
|
||||
// smDefaultMsgID := byte(0x00)
|
||||
// shortMessage := "Hello, SMPP!"
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
|
||||
conn, err := net.Dial("tcp", "localhost:2775")
|
||||
client := client.NewSMPPClient("localhost:2775", 1)
|
||||
err := client.Connect()
|
||||
if err != nil {
|
||||
log.Printf("Failed to connect to SMPP server: %+v", err)
|
||||
return
|
||||
log.Fatalf("Failed to connect to SMPP server: %v", err)
|
||||
}
|
||||
err = client.Send(submit)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to send PDU: %v", err)
|
||||
}
|
||||
log.Printf("Connected to SMPP server")
|
||||
defer conn.Close()
|
||||
|
||||
go func() {
|
||||
conn.Write(buf.Bytes())
|
||||
data, err := conn.Read(make([]byte, 1024))
|
||||
if err != nil {
|
||||
log.Printf("Failed to read from connection: %+v", err)
|
||||
return
|
||||
}
|
||||
log.Printf("Received data: %#v", data)
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
Reference in New Issue
Block a user