Fix socket race condition which can cause bytes to be dropped

Rather than discarding data if it is not a complete packet, keep
appending until a complete packet is formed.
Merge pull request #12 from c1728p9/master

Fix socket race condition which can cause bytes to be dropped