Encode codec before writing to transport.
Merge pull request #24 from ecnahc515/fix_encode_codec

Encode codec before writing to transport.