Change Stream to NetworkStream in GetBytesFromStream and SyncMsgFactory,
and include checking stream.DataAvailable in GetBytesFromStream().