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 thetcpclientobject, seeCommunicate Binary and ASCII Data to an Echo Server Using TCP/IP.

Thetcpclientproperties and functions associated with callbacks follow.

Property or Function Purpose
NumBytesAvailable Number of bytes available to read
BytesAvailableFcn Bytes available callback function
BytesAvailableFcnCount Number of bytes of data to trigger callback
BytesAvailableFcnMode Bytes available callback trigger mode
configureCallback Set callback function and trigger condition for communication with remote host over TCP/IP
ErrorOccurredFcn Callback function triggered by error event
UserData General purpose property for user data

Related Topics