Last active
July 1, 2024 15:28
-
-
Save spy16/15e6f5f716d5d2160f90b31f5ceaace9 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 ( | |
"fmt" | |
"log" | |
"github.com/panjf2000/gnet/v2" | |
) | |
func main() { | |
echo := &echoServer{} | |
log.Fatal(gnet.Run(echo, | |
"udp://239.0.0.1:9999", | |
gnet.WithNumEventLoop(2), // running 2 loops. | |
)) | |
} | |
type echoServer struct { | |
gnet.BuiltinEventEngine | |
} | |
func (es *echoServer) OnTraffic(c gnet.Conn) gnet.Action { | |
data, err := c.Next(-1) | |
if err != nil { | |
log.Printf("faield to read: %v", err) | |
} else { | |
// this happens 2 times for every single packet i send to the above | |
// multicast address. | |
fmt.Println(string(data)) | |
} | |
return gnet.None | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment