add multi sockets
This commit is contained in:
parent
b0cd98b305
commit
17253d5555
32
main.go
32
main.go
|
@ -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,19 +53,10 @@ 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()
|
||||
}
|
||||
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)
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue