-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.go
87 lines (66 loc) · 1.83 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* ThreadedIPEchoServer
*/
package main
import (
"fmt"
"net"
"os"
"runtime"
"io/ioutil"
)
var cmdClient = &Command{
Run: runClient,
UsageLine: "client",
Short: "start up a client",
Long: "start up a client",
}
// func main() {
// if len(os.Args) != 2 {
// fmt.Fprintf(os.Stderr, "Usage: %s host:port ", os.Args[0])
// os.Exit(1)
// }
// service := os.Args[1]
// tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
// checkError(err)
// conn, err := net.DialTCP("tcp", nil, tcpAddr)
// checkError(err)
// _, err = conn.Write([]byte("HEAD / HTTP/1.0\r\n\r\n"))
// checkError(err)
// //result, err := readFully(conn)
// result, err := ioutil.ReadAll(conn)
// checkError(err)
// fmt.Println(string(result))
// os.Exit(0)
// }
// func main() {
func runClient(cmd *Command, args []string) bool {
fmt.Fprintf(os.Stderr, "number of cpus:%d:\n", NCPU)
fmt.Fprintf(os.Stderr, "number of cpus as reported by go:%d:\n", runtime.NumCPU())
runtime.GOMAXPROCS(NCPU)
tcpAddr, err := net.ResolveTCPAddr("tcp4", SERVICE)
checkError(err)
conn, err := net.DialTCP("tcp", nil, tcpAddr)
checkError(err)
// _, err = conn.Write([]byte("HEAD / HTTP/1.0\r\n\r\n"))
// checkError(err)
_, err = TtpNegotiate(conn)
if err != nil {
checkError(err)
return false
}
result, err := ioutil.ReadAll(conn)
checkError(err)
fmt.Println(string(result))
// data_listener, err := net.ListenPacket("udp", service)
// checkError(err)
// defer data_listener.Close()
// for i := 0; i < NCPU; i++ {
// go handleData(data_listener, i)
// }
var input string
fmt.Scanln(&input)
return true
}
//handle commands on the tcp connection
//this need something better than silent death upon read/write error
//for now just be an echo server