Created
May 13, 2016 11:51
-
-
Save akkijp/ea0965c0d7a2f57bf6ebb1b61acd1afa to your computer and use it in GitHub Desktop.
simple udp dump server
This file contains 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" | |
"net" | |
"os" | |
) | |
/* A Simple function to verify error */ | |
func CheckError(err error) { | |
if err != nil { | |
fmt.Println("Error: " , err) | |
os.Exit(0) | |
} | |
} | |
func main() { | |
/* Lets prepare a address at any address at port 32377*/ | |
ServerAddr,err := net.ResolveUDPAddr("udp",":32377") | |
CheckError(err) | |
/* Now listen at selected port */ | |
ServerConn, err := net.ListenUDP("udp", ServerAddr) | |
CheckError(err) | |
defer ServerConn.Close() | |
buf := make([]byte, 1024) | |
for { | |
n,addr,err := ServerConn.ReadFromUDP(buf) | |
fmt.Println("Received ",string(buf[0:n]), " from ",addr) | |
if err != nil { | |
fmt.Println("Error: ",err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment