Instrument Control Toolbox    

Example: Communicating Between Two Hosts

This example illustrates how you can use UDP objects to communicate between two hosts. Your platform is considered the local host with name doejohn.dhcp, while the other platform is considered the remote host with address 192.168.1.12. To run this example on your platform, you can use the name of your machine as the local host.

  1. Create an instrument object -- Create a UDP object for the local host.
  1. A UDP object is also created for the remote host. Note that the remote host must specify the local host name and port number.

  1. Connect to the host -- Connect u1 to the remote host. The warning occurs because you created u1 as a listener with no knowledge of u2's address.
  1. Connect u2 to the host associated with u1.

  1. Write and read data -- Communicate with u1 by writing a message.
  1. Before reading data with u1, you must configure its datagram address and datagram port. This information is available to u1 after communication is established by u2.

    You can now read the message.

    You can also write a message to u2.

  1. Disconnect and clean up -- When you no longer need u1, you should disconnect it from the host, and remove it from memory and from the MATLAB workspace.

  The UDP Object Display Writing and Reading Data