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

32
main.go
View File

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