Skip to content

Commit

Permalink
Expose serving address to clients
Browse files Browse the repository at this point in the history
If the client specified port 0 wanting an OS-assigned port (perhaps for integration testing), the client needs to be able to know which port was actually picked by the OS.
  • Loading branch information
xylo04 committed Mar 28, 2023
1 parent 31eb63a commit 64bc114
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const multicastAddr = "224.0.0.1"
const wsjtxPort = 2237

type Server struct {
conn *net.UDPConn
remoteAddr *net.UDPAddr
listening bool
ServingAddr net.Addr
conn *net.UDPConn
remoteAddr *net.UDPAddr
listening bool
}

var NotConnectedError = fmt.Errorf("haven't heard from wsjtx yet, don't know where to send commands")
Expand All @@ -37,7 +38,7 @@ func MakeServer() (Server, error) {
}

// MakeServerGiven creates a UDP connection to communicate with WSJT-X on the given address and
// port.
// port. Port 0 is allowed, and will cause the OS to assign a port number.
func MakeServerGiven(ipAddr net.IP, port uint) (Server, error) {
addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%v:%d", ipAddr, port))
if err != nil {
Expand All @@ -55,7 +56,7 @@ func MakeServerGiven(ipAddr net.IP, port uint) (Server, error) {
if conn == nil {
return Server{}, errors.New("wsjtx udp connection not opened")
}
return Server{conn, nil, false}, nil
return Server{conn.LocalAddr(), conn, nil, false}, nil
}

func (s *Server) LocalAddr() net.Addr {
Expand Down

0 comments on commit 64bc114

Please sign in to comment.