[GuiUnit] Ensure the TcpWriter socket is always disposed correctly

We want to gracefully shut down the socket when possible.