2024-08-07 03:04:57 +02:00
|
|
|
const http = require("http")
|
2019-09-25 06:39:49 +02:00
|
|
|
|
2022-08-07 02:24:40 +02:00
|
|
|
let drop_goal = 5_000
|
|
|
|
let dropped = 0
|
2019-09-25 06:39:49 +02:00
|
|
|
|
|
|
|
let query = {
|
2024-08-07 03:04:57 +02:00
|
|
|
method: "POST",
|
|
|
|
host: "127.0.0.1",
|
2022-08-07 02:24:40 +02:00
|
|
|
port: 8080,
|
2024-08-07 03:04:57 +02:00
|
|
|
path: "/events",
|
2019-09-25 06:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(() => {
|
2022-08-07 02:24:40 +02:00
|
|
|
if (dropped < drop_goal) {
|
|
|
|
let request = http
|
2024-08-07 03:04:57 +02:00
|
|
|
.request(query, response => {
|
|
|
|
response.on("data", data => {
|
|
|
|
if (data.includes("data: connected\n")) {
|
2022-08-07 02:24:40 +02:00
|
|
|
// drop connection after welcome message
|
|
|
|
dropped += 1
|
|
|
|
request.abort()
|
|
|
|
}
|
2019-09-25 06:39:49 +02:00
|
|
|
})
|
2022-08-07 02:24:40 +02:00
|
|
|
})
|
2024-08-07 03:04:57 +02:00
|
|
|
.on("error", () => {})
|
2022-08-07 02:24:40 +02:00
|
|
|
.end()
|
|
|
|
}
|
2023-03-30 04:57:54 +02:00
|
|
|
}, 0)
|
2019-09-25 06:39:49 +02:00
|
|
|
|
|
|
|
setInterval(() => {
|
2024-08-07 03:04:57 +02:00
|
|
|
http
|
|
|
|
.request({ ...query, path: "/" }, () => print_status(true))
|
2022-08-07 02:24:40 +02:00
|
|
|
.setTimeout(100, () => print_status(false))
|
2024-08-07 03:04:57 +02:00
|
|
|
.on("error", () => {})
|
2019-09-25 06:39:49 +02:00
|
|
|
}, 20)
|
|
|
|
|
|
|
|
function print_status(accepting_connections) {
|
2024-08-07 03:04:57 +02:00
|
|
|
process.stdout.write("\r\x1b[K")
|
2022-08-07 02:24:40 +02:00
|
|
|
process.stdout.write(
|
2024-08-07 03:04:57 +02:00
|
|
|
`Connections dropped: ${dropped}, accepting connections: ${accepting_connections}`,
|
2022-08-07 02:24:40 +02:00
|
|
|
)
|
2019-09-25 06:39:49 +02:00
|
|
|
}
|