Main Content

Use Callbacks for TCP/IP Communication

You can enhance the power and flexibility of your TCP/IP client by using events and callbacks. An event occurs after a condition is met and can result in one or more callbacks.

While MATLAB® is connected to a remote host with a TCP/IP client, you can use events to display a message, display data, analyze data, and so on. You can control callbacks through callback properties and callback functions. All event types have an associated callback property. Callback functions are MATLAB functions that you write to suit your specific application needs. Execute a callback when a particular event occurs by specifying the name of the callback function as the value for the associated callback property.

For an example of configuring callbacks with the tcpclient object, see Communicate Binary and ASCII Data to an Echo Server Using TCP/IP.

The tcpclient properties and functions associated with callbacks follow.

Property or FunctionPurpose
NumBytesAvailableNumber of bytes available to read
BytesAvailableFcnBytes available callback function
BytesAvailableFcnCountNumber of bytes of data to trigger callback
BytesAvailableFcnModeBytes available callback trigger mode
configureCallbackSet callback function and trigger condition for communication with remote host over TCP/IP
ErrorOccurredFcnCallback function triggered by error event
UserDataGeneral purpose property for user data

Related Topics