Browse Source

add multi sockets

master
Martin/Geno 3 years ago
parent
commit
17253d5555
No known key found for this signature in database GPG Key ID: 9D7D3C6BFF600C6A
  1. 26
      main.go

26
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,26 +53,32 @@ func main() {
pixelmatrix = getPart(pixelmatrix, partCount, partTotal, partBegin)
for s := 0; s < socketCount; s++ {
conn := createSocket(pixelmatrix)
defer conn.Close()
}
// Wait for INT/TERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
log.Println("received", sig)
}
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)
}
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)
sig := <-sigs
log.Println("received", sig)
return conn
}
func paint(conn net.Conn, pixelmatrix [][][4]uint32, xstart, ystart int) {

Loading…
Cancel
Save