2 ' Copyright (c) 2010 Apple Inc. All rights reserved.
4 ' Licensed under the Apache License, Version 2.0 (the "License");
5 ' you may not use this file except in compliance with the License.
6 ' You may obtain a copy of the License at
8 ' http://www.apache.org/licenses/LICENSE-2.0
10 ' Unless required by applicable law or agreed to in writing, software
11 ' distributed under the License is distributed on an "AS IS" BASIS,
12 ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ' See the License for the specific language governing permissions and
14 ' limitations under the License.
17 Public Class DNSServiceBrowser
18 Public WithEvents MyEventManager As New Bonjour.DNSSDEventManager
20 Private m_service As New Bonjour.DNSSDService
21 Private m_browser As Bonjour.DNSSDService
22 Private m_resolver As Bonjour.DNSSDService
27 'This call is required by the Windows Form Designer.
30 ComboBox1.SelectedIndex = 0
32 Public Sub MyEventManager_ServiceFound(ByVal browser As Bonjour.DNSSDService, ByVal flags As Bonjour.DNSSDFlags, ByVal ifIndex As UInteger, ByVal serviceName As String, ByVal regtype As String, ByVal domain As String) Handles MyEventManager.ServiceFound
33 Dim browseData As New BrowseData
34 browseData.ServiceName = serviceName
35 browseData.RegType = regtype
36 browseData.Domain = domain
37 ServiceNames.Items.Add(browseData)
39 Public Sub MyEventManager_ServiceLost(ByVal browser As Bonjour.DNSSDService, ByVal flags As Bonjour.DNSSDFlags, ByVal ifIndex As UInteger, ByVal serviceName As String, ByVal regtype As String, ByVal domain As String) Handles MyEventManager.ServiceLost
40 ServiceNames.Items.Remove(serviceName)
42 Public Sub MyEventManager_ServiceResolved(ByVal resolver As Bonjour.DNSSDService, ByVal flags As Bonjour.DNSSDFlags, ByVal ifIndex As UInteger, ByVal fullname As String, ByVal hostname As String, ByVal port As UShort, ByVal record As Bonjour.TXTRecord) Handles MyEventManager.ServiceResolved
45 Dim browseData As BrowseData = ServiceNames.Items.Item(ServiceNames.SelectedIndex)
46 NameField.Text = browseData.ServiceName
47 TypeField.Text = browseData.RegType
48 DomainField.Text = browseData.Domain
49 HostField.Text = hostname
52 If record IsNot Nothing Then
53 For i As UInteger = 0 To record.GetCount() - 1
54 Dim key As String = record.GetKeyAtIndex(i)
55 If key.Length() > 0 Then
56 TextRecord.Items.Add(key + "=" + System.Text.Encoding.ASCII.GetString(record.GetValueAtIndex(i)))
61 Private Sub ClearServiceInfo()
62 TextRecord.Items.Clear()
69 Private Sub ServiceNames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServiceNames.SelectedIndexChanged
70 If m_resolver IsNot Nothing Then
74 Dim browseData As BrowseData = ServiceNames.Items.Item(ServiceNames.SelectedIndex)
75 m_resolver = m_service.Resolve(0, 0, browseData.ServiceName, browseData.RegType, browseData.Domain, MyEventManager)
77 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
78 If m_browser IsNot Nothing Then
82 ServiceNames.Items.Clear()
84 m_browser = m_service.Browse(0, 0, ComboBox1.Items.Item(ComboBox1.SelectedIndex), "", MyEventManager)
87 Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextRecord.SelectedIndexChanged
91 Public Class BrowseData
92 Private m_serviceName As String
93 Private m_regType As String
94 Private m_domain As String
96 Property ServiceName() As String
100 Set(ByVal Value As String)
101 m_serviceName = Value
105 Property RegType() As String
109 Set(ByVal Value As String)
114 Property Domain() As String
118 Set(ByVal Value As String)
123 Public Overrides Function ToString() As String