Skip to content

Instantly share code, notes, and snippets.

@rafrombrc
Created September 12, 2014 21:16
Show Gist options
  • Save rafrombrc/a8bdf4fc3f47e77fde9e to your computer and use it in GitHub Desktop.
Save rafrombrc/a8bdf4fc3f47e77fde9e to your computer and use it in GitHub Desktop.
listen testing
package main
import (
"log"
"net"
"time"
)
func accept(l net.Listener, sigBack chan struct{}) {
conn, err := l.Accept()
log.Println("past accept: ", conn)
if err != nil {
log.Println("accept error: ", err)
}
close(sigBack)
}
func main() {
l, err := net.Listen("tcp", "127.0.0.1:44444")
if err != nil {
log.Fatalln("listen error: ", err)
}
sigBack := make(chan struct{})
go accept(l, sigBack)
time.Sleep(2 * time.Second)
l.Close()
<-sigBack
log.Println("clean exit")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment