bufio.ReadString gives me EOF?

Hi, I’m trying to send a string from a client to a server over network. But it always gives me EOF and no error. Can someone tell me what I am doing wrong?


reader := bufio.NewReader(conn)
recieved, err := reader.ReadString(’\n’)
if err != nil {
fmt.Printf(“recieved %s\n”, recieved)


writer := bufio.NewWriter(server_connection)
bw, err := writer.WriteString(“woah hi there!\n”)
if err != nil {

output server:


output client:

15 written

Edit: I figured out that the EOF is actually an error which is caught. I don’t know why it is an error though

While EOF is formally returned as an error, it actually just says that the reader reached the end of the file.
But still, according to the documentation, you should not get an error if the input ends in the delimiter.

If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadString returns err != nil if and only if the returned data does not end in delim.

(from https://golang.org/pkg/bufio/#Reader.ReadString)

What is the value of received when err is EOF? From looking at the code, it should be 15 (ie, the full length of the input string).

Show more code, a full program that reproduces the issue. Are you flushing the sending buffer before closing the connection, for example?

Sorry for being late - that was pretty much the code. But I got told on IRC that using encode to json or gob was a better option and that had worked! I will try flushing after WriteString and see what happens.