SocketIO: test
This commit is contained in:
		
							
								
								
									
										1
									
								
								runsockettest.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										1
									
								
								runsockettest.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					uwsgi --http :8001 --gevent 1000 --http-websockets --master --wsgi-file socketiotest.py --callable app
 | 
				
			||||||
							
								
								
									
										19
									
								
								socketiotest.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								socketiotest.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					from flask import Flask, render_template
 | 
				
			||||||
 | 
					from flask_socketio import SocketIO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = Flask(__name__)
 | 
				
			||||||
 | 
					socketio = SocketIO(app)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route("/")
 | 
				
			||||||
 | 
					def index():
 | 
				
			||||||
 | 
					    return render_template("socketio.html")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@socketio.on('my event')
 | 
				
			||||||
 | 
					def handle_my_custom_event(json):
 | 
				
			||||||
 | 
					    print('received json: ' + str(json))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					    socketio.run(host="0.0.0.0", port=8001, app=app)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										14
									
								
								templates/socketio.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								templates/socketio.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					<html>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
 | 
				
			||||||
 | 
						<script type="text/javascript" charset="utf-8">
 | 
				
			||||||
 | 
							    var socket = io();
 | 
				
			||||||
 | 
					    socket.on('connect', function() {
 | 
				
			||||||
 | 
						            socket.emit('my event', {data: 'I\'m connected!'});
 | 
				
			||||||
 | 
						        });
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ahoj3
 | 
				
			||||||
 | 
					<input type="button" onClick="socket.emit('my event', 'test');" value="test" />
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
		Reference in New Issue
	
	Block a user