Ensure frames can not be interspersed on send

Address #507 by adding a write lock and making message sending append to the output buffer directly instead of frame-by-frame.