I'm writing a "binary echo server" and I've tried several ways to continuously read binary data from a connection and echo that data back, and for whatever reason upon writing the data, it's not making it to the other side until the connection is closed. Here is the handler method for the connection. As you can see I'm trying to read byte by byte (after several other attempts using io.Copy() failed.
func handle_relay_connection(instance *ServerInstance, conn *net.TCPConn) {
var err error
var b byte
defer conn.Close()
reader := bufio.NewReader(conn)
writer := bufio.NewWriter(conn)
for run_loop := true; run_loop; {
b, err = reader.ReadByte()
if err != nil {
if err != io.EOF {
logError("Problem reading data from connection %s: %v", instance.address, err)
} else {
logWarning("Client %s ended connection: %v", instance.address, err)
}
run_loop = false
}
writer.WriteByte(b)
writer.Flush()
}
}