Fookiwara
(Fookiwara)
1
Hello,
I need to test if a Tcp server handles multi clients connexions correctly.
Is it possible to use goroutines like this?
func SendMsg(msg string) {
conn, _ := net.Dial(“tcp”, “:1123”)
conn.Write([]byte(msg))
conn.Close()
}
for i := 0; i < 50; i++ {
go SendMsg(“test”)
}
when I try something like this, the program panics.
Regards
Fookiwara
(Fookiwara)
3
Go: panic: runtime error: invalid memory address or nil pointer dereference
NobbZ
(Norbert Melzer)
4
Perhaps check the err
returned by net.Dial
, it’s returned for a reason…
iegomez
(Ignacio Gómez)
5
Norbert beat me to it: it does sound like your conn is nil, like here: https://play.golang.org/p/mJSIcJLDpTD. Remove the return
and it will panic.
1 Like
system
(system)
Closed
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.