Browse Source

socketio for testing message transport only

master
jfinn 10 months ago
parent
commit
8521a5195e
6 changed files with 147 additions and 7 deletions
  1. 44
    3
      flask_server/app.py
  2. 50
    0
      flask_server/app_sio.py
  3. 3
    0
      js_client/ev_inc.js
  4. 5
    4
      js_client/jsync_demo.js
  5. 11
    0
      js_client/jsync_t1.js
  6. 34
    0
      js_client/sto_only.html

+ 44
- 3
flask_server/app.py View File

@@ -43,15 +43,47 @@ def index():
43 43
 # r'''
44 44
 @app.route('/shared_libs/<path:path>')
45 45
 def send_report2(path):
46
+	p("?????")
47
+	# p("?????")
46 48
 	return flask.send_file('../js_client/jquery-3.5.1.min.js')
47 49
 
50
+@app.route('/viewsrc2/<path:path>')
51
+def view_src2(path):
52
+	p(">>>>>>>>>>>>>>>>>>>>????????",path)
53
+	# return flask.send_from_directory('templates', path)
54
+	# open()
55
+
56
+	with open(r"../js_client/" + path, "r") as file:
57
+		ftxt = file.read()
58
+		# r["is_template"] = is_template_ftxt(ftxt)
59
+
60
+	# ret= flask.send_from_directory(r"../js_client", path)
61
+	# p("view_src",type(ret),ret)
62
+
63
+	return "<plaintext>" + ftxt + "</plaintext>"
64
+	return "<xmp>" + ftxt + "</xmp>"
65
+	return "<code>" + ftxt + "</code>"
66
+	return "<pre><code>" + ftxt + "</code></pre>"
67
+
68
+
69
+
48 70
 @app.route('/<path:path>')
49 71
 def send_report(path):
72
+	p("????,...",path)
50 73
 	# return flask.send_from_directory('templates', path)
51 74
 	return flask.send_from_directory(r"../js_client", path)
52 75
 	return flask.send_from_directory('./', path)
53 76
 # '''
54 77
 
78
+@app.route('/viewsrc/<path:path>')
79
+def view_src(path):
80
+	p(">>>>>>>>>>>>>>>>>>>>????????")
81
+	# return flask.send_from_directory('templates', path)
82
+	ret= flask.send_from_directory(r"../js_client", path)
83
+	p("view_src",ret)
84
+	return ret
85
+
86
+
55 87
 
56 88
 @sock.route('/echo')
57 89
 def echo(sock):
@@ -70,6 +102,7 @@ def echo_all(sock):
70 102
 		gmod.gx.send_to_channel("echo_all",data,"sender")
71 103
 
72 104
 
105
+
73 106
 # @sock.route('/echo_c1')
74 107
 # def echo_coll(sock):
75 108
 # 	p("echo_coll app")
@@ -101,9 +134,9 @@ for en in dir(app):
101 134
 	print("~",en)
102 135
 '''
103 136
 
137
+import inspect
104 138
 
105
-
106
-
139
+p(inspect.getsource(app.route))
107 140
 
108 141
 
109 142
 
@@ -121,10 +154,12 @@ def list_directory():
121 154
 	# Create an HTML string with the list of items as links
122 155
 	html_content = "<h1>Contents of the Directory</h1><ul>"
123 156
 	html_links = ""
157
+	html_src_links = ""
124 158
 	other_links = ""
125 159
 	for item in items:
126 160
 		p([item])
127 161
 		if "html" in item:
162
+			html_src_links += f"<li><a href='viewsrc2/{item}'>src:{item}</a></li>"
128 163
 			html_links += f"<li><a href='{item}'>{item}</a></li>"
129 164
 		else:
130 165
 			other_links += f"<li><a href='{item}'>{item}</a></li>"
@@ -132,6 +167,11 @@ def list_directory():
132 167
 	html_content+=html_links
133 168
 	html_content+="<br>"
134 169
 	html_content+=other_links
170
+	html_content+="<br>"
171
+	html_content+="VIEW SRC: its actually < pre >"
172
+	html_content+="<br>"
173
+	html_content+="<br>"
174
+	html_content+=html_src_links
135 175
 	html_content += "</ul>"
136 176
 
137 177
 	# Return the HTML content directly
@@ -155,7 +195,8 @@ if __name__ == '__main__':
155 195
 	pass
156 196
 	# socketio.run(app, debug=True)
157 197
 	# app.run(debug=True,host='0.0.0.0')
158
-	app.run(debug=True,host='0.0.0.0')
198
+	# app.run(debug=True,host='0.0.0.0',port="5001")
199
+	app.run(debug=True,host='0.0.0.0',port="5000")
159 200
 	# sock.run(app,host='0.0.0.0', debug=True,allow_unsafe_werkzeug=True)
160 201
 
161 202
 

+ 50
- 0
flask_server/app_sio.py View File

@@ -0,0 +1,50 @@
1
+from flask import Flask, render_template
2
+from flask_socketio import SocketIO
3
+
4
+import flask
5
+
6
+app = Flask(__name__,template_folder = r"../js_client")
7
+app.config['SECRET_KEY'] = 'secret!'
8
+socketio = SocketIO(app)
9
+
10
+p=print
11
+
12
+@app.route('/')
13
+def index():
14
+    print("INDEX")
15
+    return render_template('index.html')
16
+
17
+@app.route('/f1/<path:path>')
18
+def r2(path):
19
+    p("????,...",path)
20
+    return flask.send_file(r"../js_client/"+ path)
21
+    return flask.send_file(r"../js_client", path)
22
+    return flask.send_file('../js_client/jquery-3.5.1.min.js')
23
+    # return flask.send_from_directory('templates', path)
24
+    return flask.send_from_directory('./', path)
25
+
26
+
27
+@app.route('/<path:path>')
28
+def r1(path):
29
+    p("????,aaaa,...",path)
30
+    return flask.send_from_directory(r"../js_client", path)
31
+    return flask.send_file('../js_client/jquery-3.5.1.min.js')
32
+    # return flask.send_from_directory('templates', path)
33
+    return flask.send_from_directory('./', path)
34
+
35
+
36
+@socketio.on('message')
37
+def handle_message(data):
38
+	print('received message: ' + data)
39
+
40
+
41
+@socketio.on('json')
42
+def handle_json(json):
43
+	print('received json: ' + str(json))
44
+
45
+
46
+
47
+
48
+if __name__ == '__main__':
49
+    socketio.run(app,debug=True,host='0.0.0.0')
50
+

+ 3
- 0
js_client/ev_inc.js View File

@@ -13,6 +13,9 @@ function eval_txtarea(){
13 13
 
14 14
 	// r.exe = exe
15 15
     try {
16
+      exe = exe.replace(/[“”]/g,'"')
17
+      exe = exe.replace(/[’‘]/g,"'")
18
+
16 19
       // eval($(".eval_txt")[0].value)
17 20
       r.result = eval(exe)
18 21
       r.status = 0

+ 5
- 4
js_client/jsync_demo.js View File

@@ -33,6 +33,7 @@ function jsyncdb_init_helper(){
33 33
 
34 34
 	let ws_protocol = "wss:"
35 35
 	location.protocol == "https:" ?  "was already set to wss:" : ws_protocol = "ws:"
36
+	var port = location.port || "5000"
36 37
 
37 38
 	// location.protocol ? 
38 39
 
@@ -48,10 +49,10 @@ function jsyncdb_init_helper(){
48 49
 
49 50
 
50 51
 		url:'wss://' + window.location.hostname  +`/djc_srv/ws/chat/${room_name}`,
51
-		url: `wss://${location.hostname}:5000/echo_c1${location.search}`,
52
-		url: `${ws_protocol}//${location.hostname}:5000/echo_c1${location.search}`,
53
-		url: `${ws_protocol}//${location.hostname}:5000/echo${location.search}`,
54
-		url: `${ws_protocol}//${location.hostname}:5000/echo_all${location.search}`,
52
+		url: `wss://${location.hostname}:${port}/echo_c1${location.search}`,
53
+		url: `${ws_protocol}//${location.hostname}:${port}/echo_c1${location.search}`,
54
+		// url: `${ws_protocol}//${location.hostname}:5000/echo${location.search}`,
55
+		// url: `${ws_protocol}//${location.hostname}:5000/echo_all${location.search}`,
55 56
 		// o.url = 
56 57
 		socket_name:"ws1",
57 58
 		ord:glob_u.cb.ws,

+ 11
- 0
js_client/jsync_t1.js View File

@@ -0,0 +1,11 @@
1
+// glob_u.cb.ws.reg_cb
2
+glob_u.cb = {
3
+	ws:{},
4
+}
5
+
6
+
7
+glob_u.cb.ws.reg_cb = function(){
8
+	clog("reg_cb",arguments)
9
+}
10
+
11
+

+ 34
- 0
js_client/sto_only.html View File

@@ -0,0 +1,34 @@
1
+<html itemscope itemtype="http://schema.org/Product" prefix="og: http://ogp.me/ns#" xmlns="http://www.w3.org/1999/html">
2
+  <head>
3
+
4
+<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
5
+
6
+
7
+<!-- <script class="win_keys2 win_keys_glob_attrs" src="/ign/j9/dbg/glob_attrs.js?c=00x"></script> -->
8
+
9
+
10
+<!-- <script src="/shared_libs/jquery-3.5.1.min.js"></script> -->
11
+<script src="/jquery-3.5.1.min.js"></script>
12
+
13
+
14
+    <script src="https://rld.jfidev.com/ign/j7/rldjs/rldjs5.js?v=139"></script>
15
+    <script class="rld rrld" src="https://rld.jfidev.com/ign/rls.js?c=00x"></script>
16
+    <script class="rld rrld_u" src="https://rld.jfidev.com/ign/rls_u.js?c=c50fb605ecc3903a40c4b4e8a41ab12c"></script>
17
+
18
+<script class="rld" src="/jsync_dep.js"></script>
19
+<script class="rld" src="/jsync_t1.js"></script>
20
+<script class="rld" src="/jsync_sto.js"></script>
21
+<script class="rld" src="/jsync_init.js"></script>
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+</head>
30
+<body>
31
+
32
+
33
+</body>
34
+</html>

Loading…
Cancel
Save