-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
39 lines (31 loc) · 1.06 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
<!DOCTYPE html>
<html>
<head>
<title>Chatroom</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="messages"></div>
<input type="text" id="inputMessage" placeholder="Type your message..." />
<button onclick="sendMessage()">Send</button>
<script>
const messages = document.getElementById('messages');
function displayMessage(message) {
const messageElement = document.createElement('div');
messageElement.textContent = message;
messages.appendChild(messageElement);
}
function sendMessage() {
const inputMessage = document.getElementById('inputMessage');
const message = inputMessage.value;
displayMessage(`You: ${message}`);
inputMessage.value = '';
}
const socket = new WebSocket('ws://localhost:5555');
socket.addEventListener('message', function (event) {
const message = event.data;
displayMessage(message);
});
</script>
</body>
</html>