I'm new to Golang.
I'm implementing a small TCP server, and how do I know if one of my clients closed? Should I just try to read or write and check if err is nil?
I'm new to Golang.
I'm implementing a small TCP server, and how do I know if one of my clients closed? Should I just try to read or write and check if err is nil?
That thread "Best way to reliably detect that a TCP connection is closed", using
net.Conn
for 'c
' (also seen inutils/ping.go
orlocale-backend/server.go
or many other instances):For detecting a timeout, it suggests:
Just try to read from it, and it will throw an error if it's closed. Handle gracefully if you wish!
For risk of giving away too much:
Here is a nice introduction to using the net package to make a small TCP "chat server":
"Golang Away: TCP Chat Server"