-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.go
45 lines (38 loc) · 1.22 KB
/
start.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
package slgo
import (
"fmt"
"net"
"github.com/bclswl0827/mseedio"
"github.com/bclswl0827/slgo/handlers"
)
func (s *SeedLinkServer) Start(host string, port int, compress bool) error {
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port))
if err != nil {
return err
}
defer listener.Close()
// Set packet data type to INT32 or STEIM2
packetDataType := mseedio.INT32
if compress {
packetDataType = mseedio.STEIM2
}
// Builtin implementation of command handlers
commands := map[string]SeedLinkCommand{
"END": {HasArgs: false, Handler: &handlers.END{DataType: packetDataType}},
"DATA": {HasArgs: true, Handler: &handlers.DATA{}},
"TIME": {HasArgs: true, Handler: &handlers.TIME{}},
"INFO": {HasArgs: true, Handler: &handlers.INFO{}},
"HELLO": {HasArgs: false, Handler: &handlers.HELLO{}},
"SELECT": {HasArgs: true, Handler: &handlers.SELECT{}},
"STATION": {HasArgs: true, Handler: &handlers.STATION{}},
"CAPABILITIES": {HasArgs: true, Handler: &handlers.CAPABILITIES{}},
}
for {
conn, err := listener.Accept()
if err != nil {
continue
}
client := handlers.SeedLinkClient{Conn: conn}
go s.handleConnection(&client, commands)
}
}