Created
June 1, 2017 12:48
-
-
Save furusiyya/71073589955791caa7e1a61992763bc2 to your computer and use it in GitHub Desktop.
Client I used stress testing of my server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"net" | |
"os" | |
"strconv" | |
"time" | |
) | |
// ./test <ip:port> <delay> <data> <connections count> | |
// ./test 115.186.176.139:23 5 ps 1000 | |
func main() { | |
address := os.Args[1] | |
n, err := strconv.Atoi(os.Args[2]) | |
if err != nil { | |
fmt.Println("invalid delay: ", os.Args[2]) | |
return | |
} | |
data := os.Args[3] | |
fmt.Println("Data to be sent: ", data) | |
delay := time.Duration(n) * time.Millisecond | |
connectionsCount, err := strconv.Atoi(os.Args[4]) | |
if err != nil { | |
fmt.Println("invalid connections count: ", os.Args[2]) | |
return | |
} | |
localCounter := 0 | |
a: | |
conn, err := net.Dial("tcp", address) | |
if err != nil { | |
fmt.Println("Connection nil") | |
return | |
} | |
go func() { | |
fmt.Fprintf(conn, data) | |
// listen for reply | |
message, _ := bufio.NewReader(conn).ReadString('\n') | |
fmt.Println("Message from server: ", message) | |
message, _ = bufio.NewReader(conn).ReadString('\n') | |
fmt.Println("Message from server: ", message) | |
for { | |
if conn == nil { | |
fmt.Println("+++++++++++Connection closed already") | |
break | |
} | |
fmt.Fprintf(conn, data) | |
message, _ = bufio.NewReader(conn).ReadString('\n') | |
fmt.Println("Message from server: ", message) | |
time.Sleep(1 * time.Minute) | |
} | |
}() | |
time.Sleep(delay) | |
if localCounter > connectionsCount { | |
time.Sleep(30 * time.Minute) | |
return | |
} | |
localCounter++ | |
fmt.Println("Connections initiated: ", localCounter) | |
goto a | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment