Null Socket Check

Added a check for a 'null' socket before writing.