Last active
November 11, 2019 13:14
-
-
Save DezChuang/ad028099fafda4267a8ff2f9defbbc7f 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
// 建立一個 WebSocket 物件,並連上 socket server | |
const ws = new WebSocket('ws://localhost:5566') | |
// 連線建立後 | |
ws.onopen = () => { | |
console.log('open connection to server') | |
} | |
// 連線斷開後 | |
ws.onclose = () => { | |
console.log('close connection to server') | |
} | |
// 收到 server 事件時,將事件中的訊息印出來 | |
ws.onmessage = event => { | |
console.log(event.data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment