package main
import ( "net" "log" "time")
func createClient() { tcpConn, err := net.DialTCP("tcp4", nil, &net.TCPAddr{ IP: net.IPv4(127, 0, 0, 1), Port: 12819, }) if err != nil { log.Fatalln("Error connecting to the server!") } log.Println("Managed to dial!") tcpConn.Close()}
func main() { go createClient() l, err := net.ListenTCP("tcp4", &net.TCPAddr{ IP: net.IPv4(127, 0, 0, 1), Port: 12819, }) if err != nil { log.Fatalln("Can't listen on provided IP/port!") } if err = l.SetDeadline(time.Now().Add(time.Nanosecond)); err != nil { log.Fatalln("Can't set appropriate deadline!") } tcpConn, err := l.AcceptTCP() if err != nil { if opError, ok := err.(*net.OpError); ok { if opError.Timeout() { log.Fatalln("Timeout error!") } } log.Fatalln("Error while accepting connection!") } log.Println("Accepted new connection!") tcpConn.Close()}
On 24 May 2016 8:02 a.m., <rhomo...@gmail.com> wrote:
>
> The main point is to know that my `Accept()` call wouldn't block.
That's what the normal Accept() function in the net package does.
It blocks the goroutine but not a thread by using epoll/select.
All functions in the net package are async from the perspective of a system thread.