/
server.go
71 lines (51 loc) · 1.82 KB
/
server.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
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
ot "github.com/summitto/ot-wrapper/pkg"
)
func testServer() {
fmt.Println("Starting example test server")
manager := ot.NewOTManagerGo(true, false)
defer ot.DeleteOTManagerGo(manager)
fmt.Printf("is connected: %t\n", manager.IsConnected())
fmt.Printf("is server: %t\n", manager.IsServer())
manager.Connect("127.0.0.1:12345")
fmt.Printf("is connected: %t\n", manager.IsConnected())
input := ot.NewUInt8Vector()
defer ot.DeleteUInt8Vector(input)
buffer := []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
}
for _, val := range buffer {
input.Add(val)
}
manager.RespondWithData(input)
fmt.Println("Example server test done")
}
func testClient() {
fmt.Println("Starting example test client")
manager := ot.NewOTManagerGo(false, false)
defer ot.DeleteOTManagerGo(manager)
fmt.Printf("is connected: %t\n", manager.IsConnected())
fmt.Printf("is server: %t\n", manager.IsServer())
manager.Connect("127.0.0.1:12345")
fmt.Printf("is connected: %t\n", manager.IsConnected())
choices := ot.NewUInt8Vector() // Set doesn't seem to work
defer ot.DeleteUInt8Vector(choices)
choices.Add(2) // 2 is 01 in little endian
result := manager.RequestData(choices, 2)
resultBuf := make([]byte, result.Size())
fmt.Println("Result length:", result.Size())
for i := 0; i < int(result.Size()); i++ {
resultBuf[i] = result.Get(i)
}
fmt.Println("Received bytes:", resultBuf)
fmt.Println("Example client test done")
}
func main() {
testServer()
testClient()
}