Closed Assassintears closed 4 years ago
The error tells you that str
contains a byte 0 in it (which is not a valid character).
Most likely this happens because Read()
doesn't fill the whole by
and the rest of it is filled with default 0 bytes.
Try:
n, err := tcp.conn.Read(by)
...
tcp.Ch <- string(by[:n])
It'll still fail if the bytes sent on tcp connection contains 0 byte. You might want to filter invalid chars to guard against that.
@kjk yes, I fixed the problem with your method, thank you very much
I code a tcp client desktop app, want to receive string data from the server and put it to textedit. Now the error description likes bellow when I calling AppendText of textedit.