Comments (2)
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.
Thanks a lot!
from smpp34.
Related Issues (13)
- Fix all files for golint
- How to change encoding? HOT 1
- UDH support for sending large messages HOT 4
- reconnect if the connection dropped HOT 1
- Transciever doesn't read QUERY_SM_RESP
- Development Sponsorship
- Fix reading of pdu date fields with two valid lengths
- Evaluate the use of reflection package
- PDU validation checks.
- Create random PDU generator for testing
- invalid memory address or nil pointer dereference HOT 1
- Handling Optional Parameters HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smpp34.