Proper writing to serial ports (and hopefully sockets)