-
Notifications
You must be signed in to change notification settings - Fork 0
/
natnet.go
73 lines (60 loc) · 1.46 KB
/
natnet.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
72
73
package natnet
import (
"errors"
"net"
)
// NatNet network settings
var (
SERVER_IP = "127.0.0.1"
MCAST_GRP = "239.255.42.99"
COMMAND_PORT = 1510
DATA_PORT = 1511
BUFFER_SIZE = 1024
VERSION = 0.0
)
// NatNetClient protocol receiver
type NatNetClient struct {
Address string
Port int
Dispatcher *Dispatcher
running bool
conn *net.UDPConn
}
// TODO for alt interface to bind multicast socket
// Dispatcher dispatches message
type Dispatcher struct {
handlers map[string]Handler
}
func newDispatcher() (dispatcher *Dispatcher) {
return &Dispatcher{handlers: make(map[string]Handler)}
}
// Handler for messages
type Handler interface {
// HandleMessage(msg *NatNetMessage)
}
//type HandlerFunc func(msg *NatNetMessage)
func newNatNetClient(address string, port int) (client *NatNetClient) {
return &NatNetClient{
Address: address,
Port: port,
Dispatcher: newDispatcher(),
}
}
//Close closes NatNet connection
func (client *NatNetClient) Close() error {
client.running = false
return client.conn.Close()
}
//func (self *Dispatcher) Dispatch(packet NatNetPacket) {
// fmt.Printf("natnet packet")
//}
//func (self *NatNetClient) addHandler(address string, handler HandlerFunc) error {
//return self.Dispatcher.AddMsgHandler(address, handler)
//}
// ListenAndDispatch handles packet
func (client *NatNetClient) ListenAndDispatch() error {
if client.running {
return errors.New("Client is already listning")
}
return nil
}