package main
import (
"log"
"sync"
"time"
"golang.org/x/net/websocket"
)
const numConnections = 10000
func connect(uri string, wg *sync.WaitGroup) {
defer wg.Done()
ws, err := websocket.Dial(uri, "", "http://localhost/")
if err != nil {
log.Println("Failed to connect:", err)
return
}
defer ws.Close()
_, err = ws.Write([]byte("Hello"))
if err != nil {
log.Println("Failed to send message:", err)
return
}
var msg = make([]byte, 512)
_, err = ws.Read(msg)
if err != nil {
log.Println("Failed to read message:", err)
return
}
log.Println("Received message:", string(msg))
}
func main() {
uri := "ws://localhost:3322"
var wg sync.WaitGroup
for i := 0; i < numConnections; i++ {
wg.Add(1)
go connect(uri, &wg)
time.Sleep(time.Millisecond)
}
wg.Wait()
}