Ooui-tws-port/Ooui/Client.js

17 lines
441 B
JavaScript
Raw Normal View History

2017-06-13 01:24:30 +00:00
2017-06-13 01:50:48 +00:00
// Create WebSocket connection.
2017-06-13 02:54:47 +00:00
const socket = new WebSocket ("ws://localhost:8080" + rootElementPath, "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) {
2017-06-13 03:31:47 +00:00
console.log('Message from server', JSON.parse (event.data));
2017-06-13 01:50:48 +00:00
});