Practice chat web app with Golang and Websocket
WebSocket()
: Make an instance of the websocket
const socket = new WebSocket('ws://localhost:8000')
WebSocket.send()
: Send a message to the server
socket.send('Hello, server!')
WebSocket.onopen
: This event is triggered when the WebSocket connection is successfully opened.
socket.onopen = (event) => {
console.log('WebSocket connection opened!');
};
WebSocket.onmessage
: This event is triggered when a message is received from the server.
socket.onmessage = (event) => {
console.log('Received message from server: ', event.data);
};
WebSocket.onclose
: Triggered when the WebSocket is closed.
socket.onclose = (event) => {
console.log('WebSocket connection closed!');
};
WebSocket.onerror
: This event is triggered when a WebSocket error occurs.
socket.onerror = (event) => {
console.error('WebSocket error: ', event);
};