add multi sockets

This commit is contained in:
Martin/Geno 2018-12-30 07:55:51 +01:00
parent b0cd98b305
commit 17253d5555
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 20 additions and 12 deletions

30
main.go
View File

@ -15,6 +15,7 @@ import (
var targetAddr string
var imgPath string
var goProc int
var socketCount int
var startx int
var starty int
@ -27,6 +28,7 @@ func main() {
flag.StringVar(&targetAddr, "addr", "151.217.177.136:1234", "address of target tcp")
flag.StringVar(&imgPath, "img", "", "path to image")
flag.IntVar(&goProc, "proc", 1, "count of procs (go routines)")
flag.IntVar(&socketCount, "sockets", 1, "count of sockets to target")
flag.IntVar(&startx, "start-x", 0, "move at x")
flag.IntVar(&starty, "start-y", 0, "move at y")
@ -51,20 +53,11 @@ func main() {
pixelmatrix = getPart(pixelmatrix, partCount, partTotal, partBegin)
// connection(s)
conn, err := net.Dial("tcp", targetAddr)
if err != nil {
log.Fatalf("not able to create connection: %s", err)
}
for s := 0; s < socketCount; s++ {
conn := createSocket(pixelmatrix)
defer conn.Close()
// start painting
for s := 0; s < goProc; s++ {
go paint(conn, pixelmatrix, startx, starty)
}
// Wait for INT/TERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
@ -73,6 +66,21 @@ func main() {
}
func createSocket(pixelmatrix [][][4]uint32) net.Conn {
// connection(s)
conn, err := net.Dial("tcp", targetAddr)
if err != nil {
log.Fatalf("not able to create connection: %s", err)
}
// start painting
for s := 0; s < goProc; s++ {
go paint(conn, pixelmatrix, startx, starty)
}
return conn
}
func paint(conn net.Conn, pixelmatrix [][][4]uint32, xstart, ystart int) {
for {
for x, row := range pixelmatrix {