Files
inp2025/cmds/client.go
2025-11-10 11:07:36 +08:00

46 lines
746 B
Go

package cmds
import (
"fmt"
"inp2025/tcp"
"github.com/spf13/cobra"
)
func ping() {
msgs := []string{"hello, world", "goodbye"}
for _, msg := range msgs {
fmt.Printf("client sending: '%s'\n", msg)
resp, err := tcp.Get(":8080", "/test", map[string]string{"msg": msg})
if err != nil {
panic(err)
}
fmt.Printf("server reply: '%s'\n", string(resp.Body))
}
}
func pull() {
socket, err := tcp.Dial(":8080", "/test")
if err != nil {
panic(err)
}
defer socket.Shutdown()
for i := 0; i < 5; i++ {
b, err := socket.Read()
if err != nil {
panic(err)
}
fmt.Printf("server send: '%s'\n", string(b))
}
}
var clientCmd = &cobra.Command{
Use: "client",
Run: func(cmd *cobra.Command, args []string) {
ping()
},
}