UA Bundle SDK .NET  2.2.0.255
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
Discovery – Find Servers

Description

The following dialog shows an example implementation of the method Find Servers. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

The method Find Servers can be used to connect to a running Local Discovery Server. Enter the host name of the Local Discovery Server into the input field “Host Name” at “Find Servers Request” and press the button “Find Servers”. Then all discovered servers are listed at “Find Servers Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginFindServer” instead of “FindServer”.

Sample Code

The following code connects to the Local Discovery Server running on a given host and lists all discovered servers in the output window.

try
{
// create the object used to find servers or endpoints.
Discovery discovery = new Discovery();
// clear the existing servers.
ServersLV.Items.Clear();
// this is a blocking call so show the wait cursor.
Cursor = Cursors.WaitCursor;
// look for the LDS with the default endpoint.
string ds = "opc.tcp://" + HostNameTB.Text + ":4840";
List<ApplicationDescription> servers = discovery.FindServers(ds);
// update list view.
foreach (ApplicationDescription server in servers)
{
ServersLV.Items.Add(new ListViewItem(server.ApplicationName.Text) { Tag = server });
}
// adjust the column widths.
foreach (ColumnHeader column in ServersLV.Columns)
{
column.Width = -2;
}
}
catch (Exception exception)
{
ExceptionDlg.Show(this.Text, exception);
}