Skip to content

Commit

Permalink
2024-09-30 17:59:15
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Sep 30, 2024
1 parent 9f3f5bf commit 7e2b339
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
26 changes: 25 additions & 1 deletion protocol/etch/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
20 changes: 20 additions & 0 deletions protocol/etch/engine_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 7e2b339

Please sign in to comment.