Handle protocol errors gracefully
Use memory stream for frame read and write