You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
682 B

  1. package main
  2. import (
  3. "fmt"
  4. "net"
  5. "time"
  6. )
  7. /*
  8. 模拟客户端
  9. */
  10. func main() {
  11. fmt.Println("Client Test ... start")
  12. //3秒之后发起测试请求,给服务端开启服务的机会
  13. time.Sleep(3 * time.Second)
  14. conn, err := net.Dial("tcp", "127.0.0.1:7777")
  15. if err != nil {
  16. fmt.Println("client start err, exit!")
  17. return
  18. }
  19. for {
  20. _, err := conn.Write([]byte("hahaha"))
  21. if err != nil {
  22. fmt.Println("write error err ", err)
  23. return
  24. }
  25. buf := make([]byte, 512)
  26. cnt, err := conn.Read(buf)
  27. if err != nil {
  28. fmt.Println("read buf error ")
  29. return
  30. }
  31. fmt.Printf(" server call back : %s, cnt = %d\n", buf, cnt)
  32. time.Sleep(1 * time.Second)
  33. }
  34. }