multicast

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package multicast provides utilities for network multicast.

Index

Constants

This section is empty.

Variables

View Source
var RecvAddrResolver = &AddrResolver{Addr: "224.0.0.1:1900"}
View Source
var SystemAssignedInterface bool = false

SystemAssignedInterface indicates use the system assigned multicast interface or not. InterfacesProvider will be ignored when this is true.

Functions

func SendAddr

func SendAddr() (*net.UDPAddr, error)

SendAddr returns an address to send multicast UDP package.

func SetRecvAddrIPv4

func SetRecvAddrIPv4(addr string) error

SetRecvAddrIPv4 updates multicast address where to receive packets. This never fail now.

func SetSendAddrIPv4

func SetSendAddrIPv4(addr string) error

SetSendAddrIPv4 updates a UDP address to send multicast packets. This never fail now.

Types

type AddrResolver

type AddrResolver struct {
	Addr string
	// contains filtered or unexported fields
}

type BytesDataProvider

type BytesDataProvider []byte

func (BytesDataProvider) Bytes

func (b BytesDataProvider) Bytes(ifi *net.Interface) []byte

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is multicast connection.

func Listen

func Listen(r *AddrResolver, opts ...ConnOption) (*Conn, error)

Listen starts to receiving multicast messages.

func (*Conn) Close

func (mc *Conn) Close() error

Close closes a multicast connection.

func (*Conn) LocalAddr

func (mc *Conn) LocalAddr() net.Addr

LocalAddr returns local address to listen multicast packets.

func (*Conn) ReadPackets

func (mc *Conn) ReadPackets(timeout time.Duration, h PacketHandler) error

ReadPackets reads multicast packets.

func (*Conn) WriteTo

func (mc *Conn) WriteTo(dataProv DataProvider, to net.Addr) (int, error)

WriteTo sends a multicast message to interfaces.

type ConnOption added in v0.0.5

type ConnOption interface {
	// contains filtered or unexported methods
}

ConnOption is option for Listen()

func ConnSystemAssginedInterface added in v0.0.5

func ConnSystemAssginedInterface() ConnOption

func ConnTTL added in v0.0.5

func ConnTTL(ttl int) ConnOption

ConnTTL returns as ConnOption that set default TTL to the connection.

type DataProvider

type DataProvider interface {
	Bytes(*net.Interface) []byte
}

DataProvider provides a body of multicast message to send.

type InterfacesProviderFunc

type InterfacesProviderFunc func() []net.Interface
var InterfacesProvider InterfacesProviderFunc

InterfacesProvider specify a function to list all interfaces to multicast. If no provider are given, all possible interfaces will be used.

type PacketHandler

type PacketHandler func(net.Addr, []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL