-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
36 lines (32 loc) · 1.17 KB
/
Copy pathindex.html
File metadata and controls
36 lines (32 loc) · 1.17 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.5">
<title>Socket IO</title>
<!-- Socket CDN -->
<script src="https://cdn.socket.io/4.8.1/socket.io.min.js" integrity="sha384-mkQ3/7FUtcGyoppY6bz/PORYoGqOl7/aSUMn2ymDOJcapfS6PHqxhRTMh1RR0Q6+" crossorigin="anonymous"></script>
</head>
<body>
<div class="continer">
<div class="message" id="message"></div>
<div class="cta-section">
<input type="text" name="input-box" id="text-box" />
<button type="button" onclick="sendData()">Send</button>
</div>
</div>
<script>
const socket = io('http://localhost:3000/');
function sendData(){
let data = document.getElementById('text-box').value;
socket.emit('message', data);
}
// Receice from message
socket.on('message', function (data) {
const messageElement = document.createElement("p");
messageElement.textContent = data;
document.getElementById("message").appendChild(messageElement);
});
</script>
</body>
</html>