-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
64 lines (42 loc) · 1.03 KB
/
client.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
// simple client test
package main
import (
"bufio"
"fmt"
"net"
"os"
)
func logTrim(thisStr string) {
fmt.Printf(thisStr)
}
func sendRecv(conn net.Conn, sendStr string) {
logTrim("send: " + sendStr)
sendThis := []byte(sendStr)
conn.Write(sendThis)
reader := bufio.NewReader(conn)
stats, err := reader.ReadString('\n')
if err != nil {
fmt.Println("error " + err.Error())
}
logTrim("recv: " + stats)
}
func main() {
fmt.Println("start")
// 4000 is the client we connect to
conn, err := net.Dial("tcp", "localhost:4000")
if err != nil {
fmt.Printf("couldn't dial: " + err.Error() + "\n")
os.Exit(0)
}
sendRecv(conn, "con localhost:4002\n")
sendRecv(conn, "con localhost:4001\n")
sendRecv(conn, "put thiskey thisval\n")
sendRecv(conn, "get thiskey\n")
sendRecv(conn, "del thiskey\n")
sendRecv(conn, "get thiskey\n")
sendRecv(conn, "put otherkey otherval\n")
sendRecv(conn, "put blahkey blahval\n")
sendRecv(conn, "put checkkey checkval\n")
sendRecv(conn, "put emptykey emptyval\n")
conn.Close()
}