A library that creates server abstracting the transport layer protocols
Supported protocols
Check out the CHANGELOG.
go get github.com/ednailson/transporter-go
server, _ := transporter.New("udp", "127.0.0.1", 3399)
It will create a UDP server on 127.0.0.1
at the 3399
port
The first parameter is the protocol, the library only supports tcp
, tcp4
, tcp6
, udp
, udp4
or udp6
.
you need to create the handler function to handle the received requests.
After creating the server and the handler function, you just need to start listening to receive the messages.
//Printing all the received messages
fn := func(conn connection.Connection) {
log.Println(string(conn.Message()))
}
//Starting to listen
_ = server.Listen(fn)
It will print all the received messages on the server
You just need to call the Close()
function on the server
_ = server.Close()