-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetspeed.go
60 lines (50 loc) · 1.46 KB
/
netspeed.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
package main
import (
"flag"
"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
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()
if (*caddress == "" && *saddress == "") ||
(*caddress != "" && *saddress != "") {
flag.PrintDefaults()
}
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()
}
} else if *saddress != "" {
wg.Add(1)
server.ServerMain(*saddress, *transferType, &wg)
}
wg.Wait()
}