write with Fprintf instead of conn + sprintf