Last active
August 29, 2015 14:17
-
-
Save metasov/b3f407c37049a3fc4d38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net" | |
"golang.org/x/net/ipv4" | |
) | |
func main() { | |
log.Println("Main starting...") | |
conn, err := net.ListenPacket("udp4", "0.0.0.0:1234") | |
if err != nil { | |
log.Panic("Cannot bind to listen to multicast") | |
} | |
defer conn.Close() | |
packetConn := ipv4.NewPacketConn(conn) | |
if err := packetConn.SetControlMessage(ipv4.FlagDst, true); err != nil { | |
log.Fatal("Cannot set FlagDst on connection") | |
} | |
log.Println("Starting to listen to Multicast") | |
buffer := make([]byte, 1500) | |
for i:=1; i<2000000; i++ { | |
_, _, _, err := packetConn.ReadFrom(buffer) | |
if err != nil { | |
log.Fatal("Cannot read from UDP socket, err=", err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment