fixing heartbeats and potential disconnects during publishing

This change also suppresses warnings when writing to sockets, in favor of the exceptions that are thrown during application code error checking.
I moved this up and out because technically `$size` and `$frameType` weren't getting initialized and my IDE was complaining.