Skip to content

holoplot/go-sap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

godoc license

go-sap

A Go package to decode and encode SAP packets as described in RFC 2974.

Example

Also see the demo applications in the cmd/ folder.

Encode and send

import "github.com/holoplot/go-sap/pkg/sap"

func main() {
	sdp := []byte{
		// your SDP here
	}

	p := &sap.Packet{
		Type:        sap.MessageTypeAnnouncement,
		IDHash:      0x2342,
		Origin:      net.ParseIP("192.168.1.100"),
		PayloadType: sap.SDPPayloadType,
		Payload:     sdp,
	}

	s, err := sap.NewSender(net.ParseIP("239.255.255.255"), p)
	if err != nil {
		panic(err)
	}

	s.AnnouncePeriodically(context.Background())
}

Receive and decode

import "github.com/holoplot/go-sap/pkg/sap"

func main() {
	l, err := sap.NewListener(net.ParseIP("239.255.255.255"), nil)
	if err != nil {
		panic(err)
	}

	for {
		b, err := l.ReadPacketRaw()
		if err != nil {
			panic(err)
		}

		p, err := sap.DecodePacket(b)
		if err != nil {
			panic(err)
		}

		// Use the content of the packet
	}
}

License

MIT

About

Golang package to decode and encode SAP announcements according to RFC 2974

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages