Last active
August 8, 2019 11:24
-
-
Save psvmcc/05c18f19a60ae87ba3ffbddc9cb337b8 to your computer and use it in GitHub Desktop.
kittenhouse udp example
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 ( | |
"log" | |
"net" | |
"hash/crc32" | |
"encoding/binary" | |
) | |
func main() { | |
hostName: = "localhost" | |
portNum: = "13338" | |
service: = hostName + ":" + portNum | |
RemoteAddr, | |
err: = net.ResolveUDPAddr("udp", service) | |
conn, | |
err: = net.DialUDP("udp", nil, RemoteAddr) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Printf("Established connection to %s \n", service) | |
log.Printf("Remote UDP address : %s \n", conn.RemoteAddr().String()) | |
log.Printf("Local UDP client address : %s \n", conn.LocalAddr().String()) | |
defer conn.Close() | |
//message := []byte(string(1)) | |
//message = append(message, "goflow.test"...) | |
message: = [] byte("goflow.test") | |
message = append(message, ([] byte(string(0)))...) | |
message = append(message, "('127.0.0.1','127.0.0.2')"...) | |
buf: = make([] byte, 4) | |
v: = crc32.Update(0, crc32.IEEETable, message) | |
binary.LittleEndian.PutUint32(buf, v) | |
message = append(message, buf...) | |
_, | |
err = conn.Write(message) | |
if err != nil { | |
log.Println(err) | |
} | |
} |
Author
psvmcc
commented
Aug 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment