File size: 830 Bytes
783bbf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html>
<head>
    <title>Flask SocketIO Chat</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.1.2/socket.io.js"></script>
    <script>
        var socket = io();

        function sendMessage() {
            var message = document.getElementById("messageInput").value;
            socket.emit('message', message);
            document.getElementById("messageInput").value = '';
        }

        socket.on('message', function(message) {
            var chat = document.getElementById('chat');
            var p = document.createElement('p');
            p.innerText = message;
            chat.appendChild(p);
        });
    </script>
</head>
<body>
    <div id="chat"></div>
    <input type="text" id="messageInput" />
    <button onclick="sendMessage()">Send</button>
</body>
</html>