On Sat, Jun 20, 2020 at 3:47 PM <hardconnect....@gmail.com> wrote:

> Can you have multiple go routines waiting to read from a socket, or are
> you limited to just one?
>

Yes, you can have multiple readers of a socket. But the results will be
unpredictable. Especially if it's a SOCK_STREAM (e.g., TCP) socket. You
should only do that if it's a SOCK_DGRAM (e.g., UDP) socket but even then
you won't be able to predict which goroutine reads a particular packet.
Note that this doesn't really have anything to do with Go. It's just how
network sockets work and the answer is the same if the language was C/C++.
Your question is equivalent to asking if you can have multiple goroutines
reading from the same file descriptor opened on a pipe. The answer is, yes,
but as with sockets you'll get unpredictable results.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_CjYC%3DYZsPWJzkyGhqZxRCCe21g5b91V7rPXENLX1seA%40mail.gmail.com.

Reply via email to