-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
39 lines (35 loc) · 821 Bytes
/
main.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
package main
import (
"flag"
"github.com/dddpaul/gonc/tcp"
"github.com/dddpaul/gonc/udp"
)
func main() {
var host, port, proto string
var listen bool
flag.StringVar(&host, "host", "", "Remote host to connect, i.e. 127.0.0.1")
flag.StringVar(&proto, "proto", "tcp", "TCP/UDP mode")
flag.BoolVar(&listen, "listen", false, "Listen mode")
flag.StringVar(&port, "port", ":9999", "Port to listen on or connect to (prepended by colon), i.e. :9999")
flag.Parse()
switch proto {
case "tcp":
if listen {
tcp.StartServer(proto, port)
} else if host != "" {
tcp.StartClient(proto, host, port)
} else {
flag.Usage()
}
case "udp":
if listen {
udp.StartServer(proto, port)
} else if host != "" {
udp.StartClient(proto, host, port)
} else {
flag.Usage()
}
default:
flag.Usage()
}
}