Skip to content

Instantly share code, notes, and snippets.

@psvmcc
Last active August 8, 2019 11:24
Show Gist options
  • Save psvmcc/05c18f19a60ae87ba3ffbddc9cb337b8 to your computer and use it in GitHub Desktop.
Save psvmcc/05c18f19a60ae87ba3ffbddc9cb337b8 to your computer and use it in GitHub Desktop.
kittenhouse udp example
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)
}
}
@psvmcc
Copy link
Author

psvmcc commented Aug 8, 2019

CREATE TABLE goflow.test (src String, dst String) ENGINE = Memory
go run udp2kitten.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment