MCPcopy
hub / github.com/hwholiday/learning_tools / Test

Function Test

tcp/howie_test.go:14–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func Test(t *testing.T) {
15 conn, err := net.Dial("tcp", "192.168.2.28:8111")
16 if err != nil {
17 log.Println("dial error:", err)
18 return
19 }
20 defer conn.Close()
21 go func() {
22 /*for {*/
23 data, err := Encode("2")
24 if err == nil {
25 time.Sleep(time.Second * 4)
26 _, err := conn.Write(data)
27 if err != nil {
28 fmt.Println(err)
29 }
30 }
31
32 /*}*/
33 }()
34
35 reader := bufio.NewReader(conn)
36 for {
37 tag ,data, err := Read(reader)
38 if err != nil {
39 fmt.Println(err)
40 return
41 }
42 fmt.Println(tag)
43 fmt.Println(string(data))
44 }
45
46}
47func Encode(message string) ([]byte, error) {
48 // 读取消息的长度
49 var length = int32(len(message))

Callers

nothing calls this directly

Calls 4

EncodeFunction · 0.85
ReadFunction · 0.85
WriteMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected