client_tcp_pack_windows_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //go:build windows
  2. package yu_hpsocket
  3. import (
  4. "fmt"
  5. "testing"
  6. "time"
  7. )
  8. func TestHPsocketTcpPackClient(t *testing.T) {
  9. j_client := NewTcpPackClient()
  10. fmt.Println(j_client.Create(false))
  11. j_client.OnPrepareConnect(func(t *TcpPackClient, Sender, ConnID, socket uintptr) HR {
  12. fmt.Println("j_client.OnPrepareListen", ConnID, socket)
  13. return HR_OK
  14. })
  15. j_client.OnConnect(func(t *TcpPackClient, Sender, ConnID uintptr) HR {
  16. fmt.Println("j_client.OnConnect", ConnID)
  17. return HR_OK
  18. })
  19. j_client.OnHandShake(func(t *TcpPackClient, Sender, ConnID uintptr) HR {
  20. fmt.Println("j_client.OnHandShake", Sender, ConnID)
  21. return HR_OK
  22. })
  23. j_client.OnSend(func(t *TcpPackClient, Sender, ConnID, Data uintptr, Length uintptr) HR {
  24. fmt.Println("j_client.OnSend", Sender, ConnID, Data, Length)
  25. return HR_OK
  26. })
  27. j_client.OnReceive(func(t *TcpPackClient, Sender, ConnID, Data uintptr, Length uintptr) HR {
  28. fmt.Println("j_client.OnReceive", Sender, ConnID, Data, Length)
  29. return HR_OK
  30. })
  31. j_client.OnClose(func(t *TcpPackClient, Sender, ConnID uintptr, Operation SO, ErrorCode int) HR {
  32. fmt.Println("j_client.OnClose", Sender, ConnID, Operation, ErrorCode)
  33. return HR_OK
  34. })
  35. // j_client.SetProxy(&yu_proxy.Info{
  36. // Host: "127.0.0.1",
  37. // Port: 808,
  38. // // User: "111",
  39. // // Pass: "111",
  40. // Type: 0,
  41. // Timeout: -1,
  42. // })
  43. // j_client.SetProxy(&yu_proxy.Info{
  44. // Host: "127.0.0.1",
  45. // Port: 1080,
  46. // // User: "111",
  47. // // Pass: "111",
  48. // Type: 1,
  49. // Timeout: -1,
  50. // })
  51. fmt.Println(j_client.Start("www.baidu.com", 80, false, "0.0.0.0", 0))
  52. // fmt.Println(j_client.Start("127.0.0.1", 8011, false, "0.0.0.0", 0))
  53. j_client.SetNoDelay(true)
  54. fmt.Println(j_client.GetLastError(), j_client.GetLastErrorDesc())
  55. fmt.Println(j_client.GetLocalAddress())
  56. fmt.Println(j_client.GetRemoteHost())
  57. j_client.SendS("213123123")
  58. fmt.Println(j_client.GetPendingDataLength())
  59. j_client.Close()
  60. time.Sleep(time.Second)
  61. }