Make sure there's a referer passed to the server. If not, ignore the request and treat it as tampered/modified. Same check in the disconnection event. This should prevent crashing of the server when there's no referer passed or if modified/malicious data is sent.