-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetspeed.go
More file actions
83 lines (72 loc) · 1.99 KB
/
netspeed.go
File metadata and controls
83 lines (72 loc) · 1.99 KB
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
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"runtime"
"sync"
"netspeed/client"
"netspeed/server"
)
var wg sync.WaitGroup
var default_address string = "127.0.0.1:8888"
var default_block_size uint32 = 64 * 1024
const autoServicePort = "1234"
func main() {
caddress := flag.String("c", "", "connect address(client)")
baddress := flag.String("B", "", "bind address(client)")
saddress := flag.String("s", "", "listen address(server)")
blocksize := flag.Uint64("b", uint64(default_block_size), "block_size")
count := flag.Int("P", 1, "count for connect")
read := flag.Bool("r", true, "connect read")
write := flag.Bool("w", true, "connect write")
transferType := flag.String("t", "tcp", "transfer type (tcp,kcp)")
onlyConnect := flag.Bool("O", false, "connect only")
flag.Parse()
noClient := *caddress == ""
noServer := *saddress == ""
if noClient && noServer {
if runtime.GOOS == "linux" {
wg.Add(1)
server.ServerMain(":"+autoServicePort, *transferType, &wg)
wg.Wait()
return
}
if runtime.GOOS == "windows" {
client.RunAutoMode()
return
}
}
if (noClient && noServer) || (!noClient && !noServer) {
flag.PrintDefaults()
return
}
onlyC := *caddress != "" && *saddress == "" && *baddress == "" &&
*count == 1 && *read && *write && *transferType == "tcp" && !*onlyConnect
if onlyC {
client.RunAutoModeWithServer(*caddress)
return
}
if *caddress != "" {
for i := 0; i < *count; i++ {
if *onlyConnect == true {
wg.Add(1)
go client.HandleOnlyConnect(*caddress, *baddress, *transferType, uint32(*blocksize), &wg)
} else {
if *read == true {
wg.Add(1)
go client.HandleRead(*caddress, *baddress, *transferType, uint32(*blocksize), &wg)
}
if *write == true {
wg.Add(1)
go client.HandleWrite(*caddress, *baddress, *transferType, uint32(*blocksize), &wg)
}
}
}
if *onlyConnect != true {
go client.DispalySpeed(*caddress)
}
} else if *saddress != "" {
wg.Add(1)
server.ServerMain(*saddress, *transferType, &wg)
}
wg.Wait()
}