MATLAB TCP Server and Python Proxy Server for OPCloud
Version 1.0.0 (6.43 KB) by
Joy
A MATLAB TCP server and a Python FastAPI proxy to run MATLAB functions remotely. Supports HTTP requests and FastAPI routing.
MATLAB TCP Server and Python Proxy Server for OPCloud
This repository provides two methods to serve MATLAB functions remotely:
1. A TCP-based MATLAB server using Java sockets.
2. A Python proxy server using FastAPI to communicate with MATLAB.
Method 1: MATLAB TCP Server
This method runs a TCP server in MATLAB to execute functions via HTTP-like requests.
Running the MATLAB TCP Server
Start the server in MATLAB on port 4000:
serve(4000);
The server will start and wait for incoming connections.
Example API Call
Call MATLAB functions remotely using an HTTP request:
Example Function (functions/displacement.m)
function s = displacement(v_init, v_final, time)
s = (v_init + v_final)/2 * time;
end
Example Request (Browser or OPCloud)
http://localhost:4000/displacement?v_init=1&v_final=5&time=2
Expected Response
6
Stopping the Server
Close the figure window to shut down the server.
Requirements
• MATLAB 2020 or later
• Java (included with MATLAB)
Method 2: Python Proxy Server
This method runs a FastAPI-based proxy server in Python, which forwards requests to MATLAB.
Installing Dependencies
Ensure you have Python installed, then install the required dependencies:
pip install -r requirements.txt
Running the Python Proxy Server
Start the FastAPI server on port 4000:
fastapi run app.py --port 4000
Making API Calls
Call MATLAB functions through HTTP requests:
http://localhost:4000/displacement?v_init=1&v_final=5&time=2
Expected Response
6
Stopping the Server
Stop the FastAPI server with CTRL+C.
Requirements
• Python 3.8 or later
• MATLAB Engine API for Python (installed automatically via requirements.txt)
Cite As
Joy (2025). MATLAB TCP Server and Python Proxy Server for OPCloud (https://se.mathworks.com/matlabcentral/fileexchange/180232-matlab-tcp-server-and-python-proxy-server-for-opcloud), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024b
Compatible with R2007b and later releases
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
functions
server_functions
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |