Skip to content

Commit

Permalink
look more like the httpserver design
Browse files Browse the repository at this point in the history
  • Loading branch information
chabad360 committed May 5, 2022
1 parent 1229c4f commit c2e3ef7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions osc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ func (s *Server) ListenAndServe() error {
return fmt.Errorf("ListenAndServe: missing handler")
}

var err error
s.conn, err = net.ListenPacket("udp", s.Addr)
conn, err := net.ListenPacket("udp", s.Addr)
if err != nil {
return err
}
defer s.Close()
//defer s.Close()

return s.Serve()
return s.Serve(conn)
}

// Serve retrieves incoming OSC packets.
func (s *Server) Serve() error {
// Serve retrieves incoming OSC packets from a net.PacketConn
func (s *Server) Serve(conn net.PacketConn) error {
s.conn = conn

var falloff time.Duration
for {
msg, addr, err := s.readFromConnection()
Expand All @@ -57,6 +58,7 @@ func (s *Server) Serve() error {
} else if !ok {
continue // TODO: allow logging of invalid packets
}
s.conn.Close()
return err
}
falloff = 0
Expand Down

0 comments on commit c2e3ef7

Please sign in to comment.