-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
62 lines (54 loc) · 1.3 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.new-class{
background-color: green;
padding: 10px;
color: white;
font-size: 20px;
text-align: center;
}
.content{
display: flex;
flex-direction: row;
justify-content: center;
}
</style>
</head>
<body>
<h1>GOlang websocket PoC</h1>
<!-- FOR BOX INPUT AND SEND BUTTON -->
<div class="content">
<input type="text" id="input">
<button onclick="send()">send message</button>
</div>
<!-- PRINT YOU MESSAGE -->
<pre id="output"></pre>
</body>
<script>
var input = document.getElementById('input')
var output = document.getElementById('output')
var socket = new WebSocket("ws://localhost:8080/ws")
// ADD STYLE IN YOU INPUT HTML
output.classList.add("new-class")
// CHECK IF YOU CONNECT TO SERVER GOLANG AND SHOW CONNECTED MESSAGE
socket.onopen = function(){
output.innerHTML += "Status : CONNECTED\n"
}
// IF YOU RECEIVE MESSAGE AND WRITE TO BROWSER
socket.onmessage = function(e){
output.innerHTML += "Message : " + e.data + "\n"
// console.log(e.data)
}
// BUTTON SEND FUNCTION
function send(){
socket.send(input.value)
// EMPTY INPUT
input.value = ""
}
</script>
</html>