File tree Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 7
7
- [ Select Single Checkbox] ( js/single-checkbox-selection.js )
8
8
- [ Datetime (Unix , RealTime and Formatted Datetime)] ( js/datetime.js )
9
9
## React JS
10
+ - [ React Socket Connection] ( react-js/Socket.js )
10
11
- [ Exportable API Endpoint] ( react-js/api/ApiHelper.js )
11
12
- [ Example API Helper Routes ] ( react-js/api/ExampleApi.js )
12
13
- [ API Integration Add Component] ( react-js/api/ApiAdd.js )
27
28
28
29
## Python
29
30
- [ Find Router Connected Ip List of] ( python/router_ip_address.py )
30
-
31
+ - [ Flask Socket Connection ] ( python/flask_socket.py )
31
32
- [ Google Cloud Pub/Sub Publishing/subscription messages and subscriptions list] ( python/pubsub.py )
32
33
- [ Dockerize Flask App] ( python/Dockerfile )
33
34
- [ Cython Compile File Generator] ( python/compile.py )
Original file line number Diff line number Diff line change
1
+ # pip install flask flask_socketio
2
+ from flask import Flask
3
+ from flask_socketio import SocketIO ,emit
4
+ import flask_socketio
5
+
6
+ app = Flask (__name__ )
7
+ socketio = SocketIO (app )
8
+
9
+
10
+ @socketio .on ('connect' )
11
+ def test_message ():
12
+ data = "asd"
13
+ emit ('my' , {data : 'got it!' })
14
+
15
+ if __name__ == '__main__' :
16
+ # app.run(debug=True)
17
+ socketio .run (app , debug = True )
18
+
Original file line number Diff line number Diff line change
1
+ // npm install socket.io-client
2
+ import React , { Component } from 'react' ;
3
+ import socketIOClient from "socket.io-client"
4
+
5
+ class Socket extends Component {
6
+
7
+ constructor ( ) {
8
+ super ( ) ;
9
+ this . state = {
10
+ response : 0 ,
11
+ endpoint : "http://localhost:5000"
12
+ } ;
13
+ }
14
+
15
+ componentDidMount ( ) {
16
+
17
+ const { endpoint} = this . state ;
18
+ const socket = socketIOClient ( endpoint ) ;
19
+ console . log ( "MOUNT" ) ;
20
+ socket . on ( "my" , function ( data ) {
21
+ console . log ( "GETTING DATA " , data ) ;
22
+ } )
23
+ }
24
+
25
+ render ( ) {
26
+
27
+ return (
28
+ < div >
29
+ Test Socket
30
+ </ div >
31
+ )
32
+ }
33
+ }
34
+ export default Socket ;
You can’t perform that action at this time.
0 commit comments