12 lines
329 B
JavaScript
12 lines
329 B
JavaScript
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const socket = new WebSocket(`${proto}//${window.location.host}/ws`);
|
|
|
|
socket.onopen = () => {
|
|
console.log('Connected to server...');
|
|
socket.send('world');
|
|
};
|
|
|
|
socket.onmessage = (e) => {
|
|
console.log('Received message from server: ', e.data);
|
|
};
|