server_tcp_pack_windows_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //go:build windows
  2. package yu_hpsocket
  3. import (
  4. "fmt"
  5. yu_fast "gogs.qqck.cn/s/tools/fast"
  6. "testing"
  7. "time"
  8. )
  9. func TestHPsocketTcpPackServer(t *testing.T) {
  10. j_server := NewTcpPackServer()
  11. fmt.Println(j_server.Create(false))
  12. j_server.OnPrepareListen(func(t *TcpPackServer, Sender, Listen uintptr) HR {
  13. fmt.Println("j_server.OnPrepareListen", Sender, Listen)
  14. return HR_OK
  15. })
  16. j_server.OnAccept(func(t *TcpPackServer, Sender, ConnID, Client uintptr) HR {
  17. fmt.Println("j_server.OnConnect", ConnID)
  18. fmt.Println(t.GetRemoteAddress(ConnID))
  19. return HR_OK
  20. })
  21. j_server.OnHandShake(func(t *TcpPackServer, Sender, ConnID uintptr) HR {
  22. fmt.Println("j_server.OnHandShake", Sender, ConnID)
  23. return HR_OK
  24. })
  25. j_server.OnSend(func(t *TcpPackServer, Sender, ConnID, Data uintptr, Length uintptr) HR {
  26. fmt.Println("j_server.OnSend", Sender, ConnID, Data, Length)
  27. return HR_OK
  28. })
  29. j_server.OnReceive(func(t *TcpPackServer, Sender, ConnID, Data uintptr, Length uintptr) HR {
  30. fmt.Println("j_server.OnReceive", Sender, ConnID, Data, Length)
  31. fmt.Println("j_server.OnSend", t.Send(ConnID, yu_fast.P2B(Data, Length)))
  32. return HR_OK
  33. })
  34. j_server.OnClose(func(t *TcpPackServer, Sender, ConnID uintptr, Operation SO, ErrorCode int) HR {
  35. fmt.Println("j_server.OnClose", Sender, ConnID, Operation, ErrorCode)
  36. return HR_OK
  37. })
  38. j_server.OnShutdown(func(t *TcpPackServer, Sender uintptr) HR {
  39. fmt.Println("j_server.OnShutdown", Sender)
  40. return HR_OK
  41. })
  42. fmt.Println(j_server.Start("0.0.0.0", 8011))
  43. fmt.Println(j_server.GetLastError(), j_server.GetLastErrorDesc())
  44. time.Sleep(time.Second * 1000 * 1000)
  45. }