package main
import (
"fmt"
"net"
)
func main() {
msg := make([]byte, 1024)
//Basic variables
port := ":2002"
protocol := "udp"
//Build the address
myaddr, err := net.ResolveUDPAddr(protocol, port)
if err != nil {
fmt.Println("Wrong Address")
return
}
//Output
fmt.Println("Reading " + protocol + " from " + myaddr.String())
//Create the connection
connection, err := net.ListenUDP(protocol, myaddr)
if err != nil {
fmt.Println(err)
}
//receive msg
for {
_, useraddr, err := connection.ReadFromUDP(msg)
fmt.Println("msg from :", useraddr)
if err != nil {
fmt.Printf("Some error %v", err)
continue
}
go sendResponse(connection, useraddr)
}
}
This is my UDP server, I'm making a game. So I want, if the client send "let's play", the server to run the go sendresponse
function. If it's not "let's play " it will not run.
I think I should compare msg
but I don't know how. Thank you :)