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 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 {
|
||||||
|
|
Loading…
Reference in New Issue