Created
July 2, 2014 22:12
-
-
Save rafrombrc/1a3f749196e66aacc94f to your computer and use it in GitHub Desktop.
throwing dice through a tcp socket
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 ( | |
"flag" | |
"log" | |
"math/rand" | |
"net" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
address := flag.String("address", "localhost:5565", "TCP connection address") | |
conn, err := net.Dial("tcp", *address) | |
defer conn.Close() | |
if err != nil { | |
log.Fatalf("Error connecting to TCP address: %s", err) | |
} | |
for { | |
n := rand.Intn(6) + 1 | |
m := rand.Intn(6) + 1 | |
p := n + m | |
out := strings.Join([]string{strconv.Itoa(p), "\n"}, "") | |
conn.Write([]byte(out)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment