This example shows how to use MATLAB® Client for MATLAB Production Server™ to invoke a MATLAB function deployed on a MATLAB Production Server instance.
MATLAB Client for MATLAB Production Server uses MATLAB Production Server add-ons to communicate between a MATLAB client and a server instance. A MATLAB Production Server add-on makes the functions in an archive deployed on MATLAB Production Server available in MATLAB. A deployed archive and its corresponding MATLAB Production Server add-on have the same name.
Installing the MATLAB
Production Server add-on in your MATLAB desktop environment allows you to use the functions from a deployed archive in
MATLAB. Installing a MATLAB
Production Server add-on creates proxy functions of the deployed functions locally. The proxy
functions manage communication between the deployed MATLAB functions and the clients that invoke the deployed functions. A proxy function
and its corresponding deployed function have the same name. Since the proxy functions are
MATLAB functions, you can call them from the MATLAB command prompt, other functions, or scripts. You can also compile the functions
and scripts that contain the proxy functions. You can install MATLAB
Production Server add-ons using the
prodserver.addon.install function at the
MATLAB command prompt or using the MATLAB
Production Server Add-On Explorer app.
Calling the proxy MATLAB function sends an HTTP request across the network to an active MATLAB Production Server instance. The server instance calls the MATLAB function in the deployable archive and passes to it the inputs from the HTTP request. The return value of the deployed MATLAB function follows the same path over the network in reverse.
The following example describes how to install MATLAB Production Server add-ons and execute a deployed MATLAB function.
Install the MATLAB Client for MATLAB Production Server support package to your MATLAB desktop environment using the MATLAB Add-On Explorer. For information about installing add-ons, see Get and Manage Add-Ons (MATLAB).
Write a MATLAB function
mymagic that uses the
magic (MATLAB) function to create a magic square. Package this function in an archive
mathfun, then deploy it on a running MATLAB
Production Server instance.
You must include a MATLAB function signature file when you create the archive. You must enable the discovery service on the server instance that hosts the archive. For information on how to create and deploy the archive, see Create a Deployable Archive for MATLAB Production Server and Share the Deployable Archive.
function m = mymagic(in) m = magic(in); end
From your MATLAB desktop environment, install the MATLAB Production Server add-on for the deployed archive using the MATLAB Production Server Add-On Explorer app. Installing the add-on makes the MATLAB functions deployed on the server available to your MATLAB client programs. The MATLAB Production Server Add-On Explorer app is different from MATLAB Add-On Explorer.
From a MATLAB command prompt, launch the MATLAB
Production Server Add-On Explorer app using the command
In the MATLAB
Production Server Add-On Explorer app, add information about the server that
hosts the deployable archive
In the Servers section, click New.
Enter the host name of the server in the Host box and the
port number in the Port box. For example, for a server running
on your local machine on port 9910, enter
Click OK to add the server.
After you add the server, you can click Check Status to check the server status.
You can add multiple servers.
After you add a server, the Servers and Add-Ons section lists the server and the MATLAB Production Server add-ons that can communicate with the server. If you add multiple servers, this sections lists all the servers and the add-ons that can communicate with each server grouped under the server that hosts them.
mathfun add-on to make the MATLAB function
mymagic from the deployable archive
mathfun available in your MATLAB client programs.
In the Add-Ons section, click Install. This installs the add-on.
After you install a MATLAB Production Server add-on, the MATLAB Add-On Manager lists it. You can perform tasks such as enabling, disabling and uninstalling the add-on, and viewing details about the add-on. Viewing the add-on in Add-On Explorer is not supported.
Installing an add-on creates proxy MATLAB functions locally that let you invoke MATLAB functions deployed on the server. You can call the proxy functions from other
MATLAB functions, scripts, or standalone applications. You can also call the proxy
functions interactively from the MATLAB command prompt. For example, to invoke the
hosted on the server, you can call the proxy
mymagic function from the
MATLAB command prompt.
This prints a 3 by 3 magic square.
You can find more examples in the
is the root folder of support packages on your system. You can access the documentation by
doc command at the MATLAB command prompt or clicking the Help button in MATLAB desktop. In the Help browser that opens, navigate to MATLAB Client for MATLAB
Production Server under Supplemental Software.