-
Notifications
You must be signed in to change notification settings - Fork 8
Frontend Backend Communication Documentation
socket.io is a module used to establish a WebSocket connection between the Flask Backend and React Frontend for dual communication. It is event-based, so it is completely asynchronous. The information must be sent through one method and must be received someplace else through a different async method. This helps prevent any block in execution in the frontend when passing data to the backend for training or processing and allows for asynchronous communication from the backend to the frontend.
In any React Component:
import { socket } from '<someRelativePath>/helper_functions/TalkWithBackend'
const MyComponent = () => {
socket.emit('eventName', data1, data2, ...)
}
In driver.py:
@socket.on('eventName')
def any_name(param1, param2, ...):
<perform_function>
The eventName needs to be the same, and you do not have to jsonify so you can directly send dictionaries as well.
You can create a function in driver.py that interacts with socket as shown below, and then pass that function as arguments for use in other backend files
def any_name(param1):
socket.emit('eventName', f'param1 is {param1}') # as an example
In a React Component that needs to intercept the data:
import { socket } from '<someRelativePath>/helper_functions/TalkWithBackend'
const MyComponent = () => {
const [data, setData] = useState(null)
useEffect(() => {
socket.on('eventName', (resultData) => {
setData(resultData)
})
}, [socket])
}
Check out driver.py and TrainButton.js for an example of its usage
Server API: Flask-SocketIO
Client API: socket.io-client
Contact @samarth52 for any socket.io related bugs.
- Home
- Terraform
- Bearer-Token-Gen-Script
- Frontend-Backend Communication Documentation
- Backend Documentation (backend)
-
driver.py
- AWS Helper Files (backend.aws_helpers)
- Dynamo DB Utility Files (aws_helpers.dynamo_db_utils)
- AWS Secrets Utility Files (aws_secrets_utils)
- AWS Batch Utility Files (aws_batch_utils)
- Firebase Helper Files (backend.firebase_helpers)
- Common Files (backend.common)
-
constants.py
-
dataset.py
-
default_datasets.py
-
email_notifier.py
-
loss_functions.py
-
optimizer.py
-
utils.py
- Deep Learning Files (backend.dl)
- Machine Learning Files (backend.ml)
- Frontend Documentation
- Bug Manual
- Developer Runbook
- Examples to locally test DLP
- Knowledge Share