2017-06-13 01:24:30 +00:00
|
|
|
|
2017-06-13 01:50:48 +00:00
|
|
|
// Create WebSocket connection.
|
|
|
|
const socket = new WebSocket ("ws://localhost:8080", "ooui-1.0");
|
2017-06-13 01:24:30 +00:00
|
|
|
|
2017-06-13 01:50:48 +00:00
|
|
|
console.log("Socket created");
|
2017-06-13 01:24:30 +00:00
|
|
|
|
2017-06-13 01:50:48 +00:00
|
|
|
// Connection opened
|
|
|
|
socket.addEventListener('open', function (event) {
|
|
|
|
console.log("Socket opened");
|
|
|
|
socket.send('Hello Server!');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Listen for messages
|
|
|
|
socket.addEventListener('message', function (event) {
|
|
|
|
console.log('Message from server', event.data);
|
|
|
|
});
|