Move syncronization to writePacketToSocket().