diff --git a/protocol/etch/engine.go b/protocol/etch/engine.go index 4287da6..6f786e9 100644 --- a/protocol/etch/engine.go +++ b/protocol/etch/engine.go @@ -20,7 +20,31 @@ func (s *Server) Run() error { if err != nil { break } - log.Println(addr, buf[:n]) + log.Println(addr, string(buf[:n])) } return nil } + +func NewServer(listen string) *Server { + return &Server{ + Listen: listen, + } +} + +type Client struct { + Server string +} + +func (s *Client) Run() { + addr := doa.Try(net.ResolveUDPAddr("udp", s.Server)) + conn := doa.Try(net.DialUDP("udp", nil, addr)) + for range 32 { + doa.Try(conn.Write([]byte("Hello World!"))) + } +} + +func NewClient(server string) *Client { + return &Client{ + Server: server, + } +} diff --git a/protocol/etch/engine_test.go b/protocol/etch/engine_test.go new file mode 100644 index 0000000..9df85ea --- /dev/null +++ b/protocol/etch/engine_test.go @@ -0,0 +1,20 @@ +package etch + +import ( + "testing" + "time" +) + +const ( + DazeServerListenOn = "127.0.0.1:28081" +) + +func TestProtocolEtch(t *testing.T) { + server := NewServer(DazeServerListenOn) + go server.Run() + time.Sleep(time.Second) + + client := NewClient(DazeServerListenOn) + client.Run() + time.Sleep(time.Second) +}