-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
20 lines (17 loc) · 820 Bytes
/
javascript.js
File metadata and controls
20 lines (17 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var webSocket = new WebSocket("ws://localhost:8080/example/hello");
var msgField = document.getElementById("messageField");
var divMsg = document.getElementById("msg-box");
function sendMsg(){
var msgToSend = msgField.value;
webSocket.send(msgToSend);
divMsg.innerHTML += "<div style = 'color:red'>Client>" +msgToSend + "</div>"
msgField.value = "";
}
webSocket.onmessage = function(message){
divMsg.innerHTML += "Server> : " + message.data;
}
webSocket.onopen = function(){console.log("connection opened")};
webSocket.onclose = function(){console.log("connection closed")};
webSocket.onerror = function wserror(message){
console.log("error: "+message);
}