jfinn 5 місяці тому
коміт
703a2b46fb
4 змінених файлів з 97 додано та 0 видалено
  1. 1
    0
      .gitignore
  2. 26
    0
      app.py
  3. 17
    0
      requirements.txt
  4. 53
    0
      templates/index.html

+ 1
- 0
.gitignore Переглянути файл

@@ -0,0 +1 @@
1
+*.pyc

+ 26
- 0
app.py Переглянути файл

@@ -0,0 +1,26 @@
1
+from flask import Flask, render_template
2
+from flask_socketio import SocketIO
3
+
4
+app = Flask(__name__)
5
+app.config['SECRET_KEY'] = 'your_secret_key'  # Replace with your own secret key
6
+
7
+socketio = SocketIO(app)
8
+
9
+@app.route('/')
10
+def index():
11
+    return render_template('index.html')
12
+
13
+@socketio.on('connect')
14
+def handle_connect():
15
+    print('Client connected')
16
+
17
+@socketio.on('message')
18
+def handle_message(data):
19
+    print('Received message:', data)
20
+    socketio.emit('response', 'Server received your message: ' + data)
21
+
22
+
23
+
24
+if __name__ == '__main__':
25
+    # socketio.run(app, debug=True)
26
+    socketio.run(app,host='0.0.0.0', debug=True,allow_unsafe_werkzeug=True)

+ 17
- 0
requirements.txt Переглянути файл

@@ -0,0 +1,17 @@
1
+async-timeout==4.0.3
2
+bidict==0.23.1
3
+blinker==1.7.0
4
+click==8.1.7
5
+colorama==0.4.6
6
+Flask==3.0.3
7
+Flask-SocketIO==5.3.6
8
+h11==0.14.0
9
+itsdangerous==2.1.2
10
+Jinja2==3.1.3
11
+MarkupSafe==2.1.5
12
+python-engineio==4.9.0
13
+python-socketio==5.11.2
14
+redis==5.0.3
15
+simple-websocket==1.0.0
16
+Werkzeug==3.0.2
17
+wsproto==1.2.0

+ 53
- 0
templates/index.html Переглянути файл

@@ -0,0 +1,53 @@
1
+<!DOCTYPE html>
2
+<html>
3
+<head>
4
+    <title>WebSocket Example</title>
5
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.1.3/socket.io.js"></script>
6
+    <script type="text/javascript">
7
+        var socket = io.connect('http://' + document.domain + ':' + location.port);
8
+
9
+
10
+        function sendMessage() {
11
+            var message = document.getElementById('message').value;
12
+            socket.emit('message', message);
13
+        }
14
+
15
+        socket.on('connect', function () {
16
+            console.log('Connected to the server');
17
+            socket.emit('message', "run_fn");
18
+        });
19
+
20
+        socket.on('response', function (data) {
21
+            console.log('Server says: ' + data);
22
+        });
23
+
24
+        clog=console.log
25
+        function rec_q_to_tab(data_str,a,b,c,d){
26
+            clog({that:this},arguments)
27
+            var data = JSON.parse(data_str)
28
+
29
+            clog(data)
30
+            lines = data.file_content.split("\n")
31
+            proc_data = {arr:[]}
32
+            for (line of lines){
33
+                if (!line){
34
+                    clog("NOT LINE",line)
35
+                    continue
36
+                }
37
+                // clog()
38
+                proc_data.arr.push(JSON.parse(line))
39
+            }
40
+
41
+
42
+        }
43
+        socket.on('q_to_tab_q', rec_q_to_tab)
44
+
45
+
46
+    </script>
47
+</head>
48
+<body>
49
+    <h1>WebSocket Example</h1>
50
+    <input type="text" id="message" placeholder="Type a message">
51
+    <button onclick="sendMessage()">Send</button>
52
+</body>
53
+</html>

Завантаження…
Відмінити
Зберегти