]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/DNSServiceBrowser.VB/DNSServiceBrowser.vb
mDNSResponder-212.1.tar.gz
[apple/mdnsresponder.git] / Clients / DNSServiceBrowser.VB / DNSServiceBrowser.vb
1 Public Class DNSServiceBrowser
2 Public WithEvents MyEventManager As New Bonjour.DNSSDEventManager
3
4 Private m_service As New Bonjour.DNSSDService
5 Private m_browser As Bonjour.DNSSDService
6 Private m_resolver As Bonjour.DNSSDService
7
8 Public Sub New()
9 MyBase.New()
10
11 'This call is required by the Windows Form Designer.
12 InitializeComponent()
13
14 ComboBox1.SelectedIndex = 0
15 End Sub
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)
22 End Sub
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)
25 End Sub
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
27 m_resolver.Stop()
28 m_resolver = Nothing
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
34 PortField.Text = port
35
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)))
41 End If
42 Next i
43 End If
44 End Sub
45 Private Sub ClearServiceInfo()
46 TextRecord.Items.Clear()
47 NameField.Text = ""
48 TypeField.Text = ""
49 DomainField.Text = ""
50 HostField.Text = ""
51 PortField.Text = ""
52 End Sub
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
55 m_resolver.Stop()
56 End If
57 Me.ClearServiceInfo()
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)
60 End Sub
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
63 m_browser.Stop()
64 End If
65
66 ServiceNames.Items.Clear()
67 Me.ClearServiceInfo()
68 m_browser = m_service.Browse(0, 0, ComboBox1.Items.Item(ComboBox1.SelectedIndex), "", MyEventManager)
69 End Sub
70
71 Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextRecord.SelectedIndexChanged
72
73 End Sub
74 End Class
75 Public Class BrowseData
76 Private m_serviceName As String
77 Private m_regType As String
78 Private m_domain As String
79
80 Property ServiceName() As String
81 Get
82 Return m_serviceName
83 End Get
84 Set(ByVal Value As String)
85 m_serviceName = Value
86 End Set
87 End Property
88
89 Property RegType() As String
90 Get
91 Return m_regType
92 End Get
93 Set(ByVal Value As String)
94 m_regType = Value
95 End Set
96 End Property
97
98 Property Domain() As String
99 Get
100 Return m_domain
101 End Get
102 Set(ByVal Value As String)
103 m_domain = Value
104 End Set
105 End Property
106
107 Public Overrides Function ToString() As String
108 Return m_serviceName
109 End Function
110
111 End Class