Test with the smpp center
This commit is contained in:
57
main.go
57
main.go
@@ -6,10 +6,12 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"smpptester/pdu"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.Lmicroseconds)
|
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to create a submit_sm PDU
|
// Function to create a submit_sm PDU
|
||||||
@@ -29,7 +31,7 @@ func createSubmitSMPDU() []byte {
|
|||||||
validityPeriod := ""
|
validityPeriod := ""
|
||||||
registeredDelivery := byte(0x01)
|
registeredDelivery := byte(0x01)
|
||||||
replaceIfPresentFlag := byte(0x00)
|
replaceIfPresentFlag := byte(0x00)
|
||||||
dataCoding := byte(0x00)
|
dataCoding := byte(0x01)
|
||||||
smDefaultMsgID := byte(0x00)
|
smDefaultMsgID := byte(0x00)
|
||||||
shortMessage := "Hello, SMPP!"
|
shortMessage := "Hello, SMPP!"
|
||||||
|
|
||||||
@@ -37,7 +39,6 @@ func createSubmitSMPDU() []byte {
|
|||||||
headerLength := 16
|
headerLength := 16
|
||||||
bodyLength := 1 + len(serviceType) + 1 + 1 + len(sourceAddr) + 1 + 1 + len(destinationAddr) + 1 + 1 + len(scheduleDeliveryTime) + 1 + len(validityPeriod) + 1 + 1 + 1 + 1 + 1 + len(shortMessage)
|
bodyLength := 1 + len(serviceType) + 1 + 1 + len(sourceAddr) + 1 + 1 + len(destinationAddr) + 1 + 1 + len(scheduleDeliveryTime) + 1 + len(validityPeriod) + 1 + 1 + 1 + 1 + 1 + len(shortMessage)
|
||||||
totalLength := headerLength + bodyLength
|
totalLength := headerLength + bodyLength
|
||||||
log.Printf("Total length: %d", totalLength)
|
|
||||||
|
|
||||||
// Create a buffer to hold the PDU
|
// Create a buffer to hold the PDU
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
@@ -136,7 +137,55 @@ func main() {
|
|||||||
// go handleConnection(conn)
|
// go handleConnection(conn)
|
||||||
// }
|
// }
|
||||||
// }()
|
// }()
|
||||||
|
submit := &pdu.SUBMIT_SM{
|
||||||
|
Header: &pdu.PDU_HEADER{
|
||||||
|
Command_length: 0,
|
||||||
|
Command_id: 4,
|
||||||
|
Command_status: 0,
|
||||||
|
Sequence_number: 1,
|
||||||
|
},
|
||||||
|
Service_type: "hehe",
|
||||||
|
Source_addr_ton: 0x01,
|
||||||
|
Source_addr_npi: 0x01,
|
||||||
|
Source_addr: "12345",
|
||||||
|
Dest_addr_ton: 0x01,
|
||||||
|
Dest_addr_npi: 0x01,
|
||||||
|
Destination_addr: "67890",
|
||||||
|
Esm_class: 0x00,
|
||||||
|
Protocol_id: 0x00,
|
||||||
|
Priority_flag: 0x00,
|
||||||
|
Schedule_delivery_time: "",
|
||||||
|
Validity_period: "",
|
||||||
|
Registered_delivery: 0x01,
|
||||||
|
Replace_if_present: 0x00,
|
||||||
|
Data_coding: 0x01,
|
||||||
|
Sm_default_msg_id: 0x00,
|
||||||
|
Short_message: "Hello, SMPP!",
|
||||||
|
}
|
||||||
|
submit.UpdateSize()
|
||||||
|
buf := pdu.ByteBufferPool.Get(submit.Size())
|
||||||
|
defer pdu.ByteBufferPool.Put(buf)
|
||||||
|
submit.Encode(buf)
|
||||||
|
log.Println(buf.Bytes())
|
||||||
log.Println(createSubmitSMPDU())
|
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 := &sync.WaitGroup{}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@@ -150,7 +199,7 @@ func main() {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
conn.Write(createSubmitSMPDU())
|
conn.Write(buf.Bytes())
|
||||||
data, err := conn.Read(make([]byte, 1024))
|
data, err := conn.Read(make([]byte, 1024))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to read from connection: %+v", err)
|
log.Printf("Failed to read from connection: %+v", err)
|
||||||
|
Reference in New Issue
Block a user