#Mac/Windows different behaviour for net.Conn.Read

9 messages · Page 1 of 1 (latest)

torpid imp
#

make the buffer tobe the same size as the payload length that you expect.
make([]byte, 10)

#

if num in num, err := (*c.con).Read(buf) is less than expected, you should read again until either an error occurred or the buffer is full.

#

that mean the payload is at least 4bytes.

#

yes, also use ReadFull function from io package to do that.

#

btw, what is (*c.con) ?

#

**net.Conn or *net.Conn? i'm sure you shouldn't dereference *net.Conn.

#

you shouldn't dereference *net.Conn

#

whats the error says?

#

oh, yup. i forgot net.Conn is an interface. my bad. you should not store pointer to an interface though.