Open Prem2868 opened 2 months ago
// Import necessary OkHttp libraries import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response;
import java.io.IOException;
// Create an OkHttpClient instance OkHttpClient client = new OkHttpClient();
// Create a request to communicate with the Python server
Request request = new Request.Builder()
.url("http://
// Execute the request and handle the response try (Response response = client.newCall(request).execute()) { // Check if the response is successful if (response.isSuccessful()) { // Handle successful response (e.g., parse data, update UI) } else { // Handle error response (e.g., log error, display message) } } catch (IOException e) { // Handle IOException (e.g., network error) }
Import necessary modules from Flask
from flask import Flask, request, jsonify
Initialize a Flask application
app = Flask(name)
Define a route for handling GET and POST requests
@app.route('/api/data', methods=['GET', 'POST']) def handle_data():
Check if the request method is POST
Run the Flask server on port 5000 and make it accessible from other devices
if name == 'main': app.run(host='0.0.0.0', port=5000)