Update message loops sample to detect all duplicate messages then stop connection when new message is not duplicate instead of running forever