我最近在玩 go 并尝试创建一些服务器来响应 tcp 连接上的客户端。
我的问题是我如何干净地关闭服务器并中断当前在以下调用中“阻塞”的 go-routine
func (*TCPListener) Accept?
Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.
这些错误也很少被记录。
最佳答案
只需 Close()
net.Listener
您从 net.Listen(...)
调用中获取并从正在执行的 goroutine 返回。
关于go - 如何中断执行 (*TCPListener) Accept 的 goroutine?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18825207/