https://github.com/donomii/brk
A UDP library with retry
https://github.com/donomii/brk
packet packets retry retry-library udp udp-client udp-server
Last synced: 2 months ago
JSON representation
A UDP library with retry
- Host: GitHub
- URL: https://github.com/donomii/brk
- Owner: donomii
- License: gpl-3.0
- Created: 2018-10-05T19:39:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T03:45:25.000Z (about 1 year ago)
- Last Synced: 2024-04-08T04:38:11.771Z (about 1 year ago)
- Topics: packet, packets, retry, retry-library, udp, udp-client, udp-server
- Language: Go
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/donomii/brk)
[](https://godoc.org/github.com/donomii/brk)# Brk
A UDP library with message retrying
## Summary
This is a UDP message-passing library that is capable of retrying messages that timeout. It works at the message level, rather than turning the connections into streams. You send a chunk of bytes to the other end, and sometime later, they receive a buffer of bytes.
## Features
Send a message to any IP address or port without having to _open_ a connection. Retry failed messages for a period of time.
## Install
go get -u github.com/donomii/Brk
## Use
```go
package mainimport (
"bufio"
"flag"
"os"
"strconv"
"fmt"
)func main() {
ip := "0.0.0.0"
port := "6000"//NOTE "ip" is the ip address to listen on. You do not provide the remote server details here!
//Same for "port"!
StartRetryServer(ip, port, processor)
}```
you also have to provide a processor function, to deal with the communication channels. Data arrives on _incoming_, and you send messages on _outgoing_```go
func processor(incoming, outgoing chan UdpMessage) {
message := []byte("Hello out there!")
remoteServ := "a.server.somwhere.com"
remotePort := "6000"
brk.SendMessage(outgoing, message, remoteServ, remotePort)//Read incoming messages and print them to the screen
go func() {
for mess := range incoming {
fmt.Printf("Incoming: %v\n", string(mess.Data))
}
}()
}
```You can send messages at any time after the server starts:
```go
brk.SendMessage(outgoing, message, remoteServ, remotePort)
```
The ```brk.SendMessage``` function is a convenience wrapper to format the outgoing packet and put it into the _outgoing_ channel.