rts-sim-testing-service/third_party/example/main.go

44 lines
771 B
Go

package main
import (
"log/slog"
"time"
"joylink.club/bj-rtsts-server/third_party/udp"
)
type TestMsg struct {
Msg string
Port int
}
func (t *TestMsg) Encode() []byte {
b := []byte(t.Msg)
// binary.BigEndian.PutUint16(b, uint16(t.Port))
return b
}
func (t *TestMsg) Decode(data []byte) error {
t.Msg = string(data)
// t.Port = int(binary.BigEndian.Uint16(data))
return nil
}
func handleUdpMsg(b []byte) {
slog.Info("udp server handle", "msg", string(b))
}
func main() {
udp.NewServer("127.0.0.1:6666", handleUdpMsg).Listen()
// client := udp.NewClient("127.0.0.1:7777")
// for i := 0; i < 1000; i++ {
// time.Sleep(time.Millisecond * 500)
// client.Send(&TestMsg{
// Msg: "test, port = 7777",
// })
// }
time.Sleep(time.Second * 60)
}