reflector.go/main.go

55 lines
937 B
Go
Raw Normal View History

package main
import (
"flag"
"log"
"math/rand"
2017-08-15 22:02:18 +02:00
"strconv"
"time"
)
func checkErr(err error) {
if err != nil {
panic(err)
}
}
func main() {
var err error
rand.Seed(time.Now().UnixNano())
2017-08-15 22:02:18 +02:00
port := DefaultPort
address := "52.14.109.125:" + strconv.Itoa(port)
serve := flag.Bool("server", false, "Run server")
blobDir := flag.String("blobdir", "", "Where blobs will be saved to")
flag.Parse()
if serve != nil && *serve {
if blobDir == nil || *blobDir == "" {
log.Fatal("-blobdir required")
}
server := NewServer(*blobDir)
log.Fatal(server.ListenAndServe(address))
return
}
client := Client{}
log.Println("Connecting to " + address)
err = client.Connect(address)
checkErr(err)
log.Println("Connected")
defer func() {
log.Println("Closing connection")
client.Close()
}()
blob := make([]byte, 2*1024*1024)
_, err = rand.Read(blob)
checkErr(err)
err = client.SendBlob(blob)
checkErr(err)
}