-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransceiver.go
More file actions
53 lines (44 loc) · 852 Bytes
/
transceiver.go
File metadata and controls
53 lines (44 loc) · 852 Bytes
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
package transceiver
import (
"fmt"
"github.com/RobotStudio/choreo/msg"
)
func send(tpc string) {
addrs := []string{"127.0.0.1:4150"}
p, err := msg.NewPublisher(tpc, &addrs)
if err != nil {
fmt.Println(err)
panic("Failed to initialize a new publisher")
}
data := make(chan []byte)
go p.Run(data)
go func() {
for i := 0; i < 10; i++ {
data <- []byte(fmt.Sprintf("%d asdf", i))
}
close(data)
}()
select {
case <-p.StopChan:
p.Stop()
case <-p.TermChan:
p.Stop()
}
}
func receiver() {
addrs := []string{"127.0.0.1:4150"}
s, err := msg.NewSubscriber("testthis", "testch", &addrs)
if err != nil {
fmt.Println(err)
panic("Failed to initialize a new subscriber")
}
select {
case d := <-s.Data:
fmt.Println(fmt.Sprintf("Data: %s", d))
case <-s.StopChan:
s.Stop()
case <-s.TermChan:
s.Stop()
}
return
}