-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_receivelogandack_test.go
63 lines (49 loc) · 1.12 KB
/
example_receivelogandack_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2023 Thierry FOURNIER (tfournier@arpalert.org)
package relp_test
import "log"
import "net"
import "github.com/thierry-f-78/go-relp"
// Show how using a loop of log message with acknoledgments offloaded by the
// RELP library
func Example_receiveLogAndAck() {
var ln net.Listener
var conn net.Conn
var err error
var opts *relp.Options
var r *relp.Relp
var msg string
// Create and validate options
opts, err = relp.ValidateOptions(&relp.Options{
Tls: relp.Opt_tls_disabled,
})
if err != nil {
log.Fatalf(err.Error())
}
// Create listen connexion
ln, err = net.Listen("tcp", "0.0.0.0:4150")
if err != nil {
log.Fatalf(err.Error())
}
// accept connection
conn, err = ln.Accept()
if err != nil {
log.Fatalf(err.Error())
}
defer conn.Close()
// Create RELP from net.Conn
r, err = relp.NewTcp(conn, opts)
if err != nil {
log.Fatal(err.Error())
}
defer r.Close()
// Receive log message loop
for {
// Receive and acknoledge log message
msg, err = r.ReceiveLogAndAck()
if err != nil {
log.Fatal(err.Error())
}
// Process log message. Here, just display it
println(msg)
}
}