1 Public Class DNSServiceBrowser
2 Public WithEvents MyEventManager As New Bonjour.DNSSDEventManager
4 Private m_service As New Bonjour.DNSSDService
5 Private m_browser As Bonjour.DNSSDService
6 Private m_resolver As Bonjour.DNSSDService
11 'This call is required by the Windows Form Designer.
14 ComboBox1.SelectedIndex = 0
16 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
17 Dim browseData As New BrowseData
18 browseData.ServiceName = serviceName
19 browseData.RegType = regtype
20 browseData.Domain = domain
21 ServiceNames.Items.Add(browseData)
23 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
24 ServiceNames.Items.Remove(serviceName)
26 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
29 Dim browseData As BrowseData = ServiceNames.Items.Item(ServiceNames.SelectedIndex)
30 NameField.Text = browseData.ServiceName
31 TypeField.Text = browseData.RegType
32 DomainField.Text = browseData.Domain
33 HostField.Text = hostname
36 If record IsNot Nothing Then
37 For i As UInteger = 0 To record.GetCount() - 1
38 Dim key As String = record.GetKeyAtIndex(i)
39 If key.Length() > 0 Then
40 TextRecord.Items.Add(key + "=" + System.Text.Encoding.ASCII.GetString(record.GetValueAtIndex(i)))
45 Private Sub ClearServiceInfo()
46 TextRecord.Items.Clear()
53 Private Sub ServiceNames_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ServiceNames.SelectedIndexChanged
54 If m_resolver IsNot Nothing Then
58 Dim browseData As BrowseData = ServiceNames.Items.Item(ServiceNames.SelectedIndex)
59 m_resolver = m_service.Resolve(0, 0, browseData.ServiceName, browseData.RegType, browseData.Domain, MyEventManager)
61 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
62 If m_browser IsNot Nothing Then
66 ServiceNames.Items.Clear()
68 m_browser = m_service.Browse(0, 0, ComboBox1.Items.Item(ComboBox1.SelectedIndex), "", MyEventManager)
71 Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextRecord.SelectedIndexChanged
75 Public Class BrowseData
76 Private m_serviceName As String
77 Private m_regType As String
78 Private m_domain As String
80 Property ServiceName() As String
84 Set(ByVal Value As String)
89 Property RegType() As String
93 Set(ByVal Value As String)
98 Property Domain() As String
102 Set(ByVal Value As String)
107 Public Overrides Function ToString() As String