(Not mine) Websockets example - see the link for where the code is from.