-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket.html
32 lines (30 loc) · 1.02 KB
/
socket.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
function SocketTest() {
//data to send : temporary json
var jsondata = '{"mood": 4, "date": "2016-11-06 23:00:25.689784"}'
console.log("jsondata set")
//create a WebSocket and open it
var connection = new WebSocket("ws://mood.gretaparks.com:8080");
//event: match method signatures for good practice; do not leave blank even if unused
connection.onopen = function (event){
connection.send(jsondata)
console.log("jsondatasent")
}
connection.onmessage = function (m) {
console.log('Received From Server: ' + m.data); //log the received message
//choose where this goes later
connection.close()
}
// connection.close()
}
SocketTest()
</script>
</body>
</html>