Last active
March 19, 2019 21:34
-
-
Save karenpeng/3bb187bc734f12ac828cca06a2825c0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wsConnection = new WebSocket('ws://localhost:3000/websocket'); | |
wsConnection.onopen = () => { | |
console.log('websocket connection is opened') | |
wsConnection.send('A'); | |
}; | |
wsConnection.onmessage = event => { | |
if (event.data === '9') { | |
setTimeout(() => { | |
wsConnection.send('A'); | |
}, 3000); | |
} | |
} | |
wsConnection.onerror = event => { | |
if (event.readyState === WebSocket.CLOSED) { | |
console.log('websocket connection is closed') | |
} | |
} | |
setTimeout(() => { | |
console.log('client closes the websocket connection'); | |
wsConnection.close(); | |
}, 30000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment