-
Notifications
You must be signed in to change notification settings - Fork 1
/
clockwall.go
71 lines (66 loc) · 1.2 KB
/
clockwall.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
package main
import (
"fmt"
"io"
"log"
"net"
"os"
"strings"
"time"
)
type host struct {
name string
address string
port string
}
func main() {
hosts := make([]host, 0)
if len(os.Args) > 1 {
for i, str := range os.Args {
if i == 0 {
continue
}
split1 := strings.Split(str, "=")
name := split1[0]
split2 := strings.Split(split1[1], ":")
address := split2[0]
port := split2[1]
hosts = append(hosts, host{name, address, port})
}
} else {
hosts = append(hosts, host{"local", "localhost", "8000"})
}
fmt.Println(hosts)
conns := make([]net.Conn, len(hosts))
for i, host := range hosts {
hoststr := host.address + ":" + host.port
conn, err := net.Dial("tcp", hoststr)
if err != nil {
log.Fatal(err)
}
defer conn.Close()
conns[i] = conn
for j := 0; j < i; j++ {
fmt.Print("\t\t\t")
}
fmt.Print(host.name)
}
fmt.Println()
for {
for i, conn := range conns {
b := make([]byte, 1024)
n, err := conn.Read(b)
if err == io.EOF {
os.Exit(0)
}
if err == nil && n > 0 {
os.Stdout.WriteString("\r")
for j := 0; j < i; j++ {
os.Stdout.WriteString("\t\t\t")
}
os.Stdout.Write(b)
}
}
time.Sleep(1 * time.Second)
}
}