Compare commits

...

2 Commits

Author SHA1 Message Date
Lexi / Zoe 4211560f20 First WebSocket client code 2018-10-27 05:13:14 +02:00
Lexi / Zoe 51238d47a1 Added jQuery 3.3.1 2018-10-27 05:00:11 +02:00
4 changed files with 10412 additions and 0 deletions

View File

@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>InstantChat</title>
<link rel="stylesheet" href="css/style.css">
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>

View File

@ -0,0 +1,45 @@
// Constants and variables
var wsUri = "ws://localhost:8765";
// Initialization
function init() {
console.log("Init...");
openWebSocket();
}
// Open WebSocket
function openWebSocket() {
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
// WebSocket event handlers
function onOpen(evt) {
console.log('Connected to ' + wsUri + '.');
text = "Meow";
console.log('Sending "' + text + '".');
websocket.send(text);
}
function onClose(evt) {
console.log("Connection closed.");
}
function onMessage(evt) {
console.log('Received: "' + evt.data + '".');
}
function onError(evt) {
console.error('Error: "' + evt.data + '".');
}
// Run script after page is loaded
$(function() {
init();
});

10364
public_html/js/jquery-3.3.1.js vendored Normal file

File diff suppressed because it is too large Load Diff

2
public_html/js/jquery-3.3.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long