Last active
March 11, 2021 20:38
-
-
Save russweas/eba9c09ed960430f3ba57f43031b64a5 to your computer and use it in GitHub Desktop.
conn.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conn.SetReadDeadline(time.Now().Add(2000 * time.Millisecond)) | |
edgeData, err := bufio.NewReader(conn).ReadString('\n') // Wait for next piece of data | |
if err == io.EOF { | |
return | |
} | |
// if err == ??? { // This is a timeout } | |
if err != nil { | |
log.Println(err) | |
break | |
} | |
// Outputs 2021/03/11 00:19:17 read tcp 127.0.0.1:6000->127.0.0.1:34624: i/o timeout | |
// SOLUTION | |
conn.SetReadDeadline(time.Now().Add(2000 * time.Millisecond)) | |
edgeData, err := bufio.NewReader(conn).ReadString('\n') // Wait for next piece of data | |
if err == io.EOF { | |
log.Println(err) | |
fmt.Println("The client closed the connection") | |
break | |
} else if os.IsTimeout(err) { | |
fmt.Println("The connection timed out") | |
break | |
} else if err != nil { | |
log.Println(err) | |
break | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment