Platforms to show: All Mac Windows Linux Cross-Platform
/MacFrameworks/NSNetService/Bonjour Browser Web2
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/NSNetService/Bonjour Browser Web2
This example is the version from Mon, 16th Jan 2022.
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/NSNetService/Bonjour Browser Web2
This example is the version from Mon, 16th Jan 2022.
Project "Bonjour Browser Web2.xojo_binary_project"
Class App Inherits WebApplication
EventHandler Sub Opening(args() as String)
Initialize
End EventHandler
Sub Initialize()
EventTimer = New EventTimer
// register test service
Const domain = "local." // default
Const type = "_test._tcp."
Const name = "My Test Service"
Const port = 12345
testService = New NSNetServiceMBS(domain, type, name, port)
testService.publish
End Sub
Property EventTimer As Timer
Property Protected testService As NSNetServiceMBS
End Class
Class EventTimer Inherits Timer
EventHandler Sub Action()
// run event loop once
NSRunLoopMBS.currentRunLoop.runOnce
System.DebugLog CurrentMethodName
End EventHandler
Sub Constructor()
me.Period = 50
me.mode = 2
End Sub
End Class
Class ServiceBrowser Inherits NSNetServiceBrowserMBS
EventHandler Sub DidFindService(service as NSNetServiceMBS, moreComing as Boolean)
List.AddRow Service.name, Service.type, Service.hostName
// make a new object so we have our events installed
dim m as new NetworkService(Service)
m.list = list
m.resolve
// keep Xojo object alive for later
services.Append m
list.RowTagAt(list.LastAddedRowIndex) = m
End EventHandler
EventHandler Sub DidNotSearch(error as Dictionary)
Break // error?
End EventHandler
EventHandler Sub DidRemoveService(service as NSNetServiceMBS, moreComing as Boolean)
System.DebugLog CurrentMethodName
dim index as integer = FindIndex(list, service)
if index >= 0 then
list.RemoveRowAt index
end if
End EventHandler
Property Protected Services() As NSNetServiceMBS
Property list As WebListBox
End Class
Class NetworkService Inherits NSNetServiceMBS
EventHandler Sub DidNotResolve(Error as Dictionary)
System.DebugLog CurrentMethodName
dim index as integer = FindIndex(list, self)
if index >= 0 then
List.CellValueAt(index, 3) = "failed"
List.CellValueAt(index, 4) = ""
end if
End EventHandler
EventHandler Sub DidResolveAddress()
System.DebugLog CurrentMethodName
dim index as integer = FindIndex(list, self)
if index >= 0 then
List.CellValueAt(index, 2) = Me.hostName
List.CellValueAt(index, 3) = Me.addressIPv4
List.CellValueAt(index, 4) = str(me.port)
end if
End EventHandler
EventHandler Sub WillResolve()
System.DebugLog CurrentMethodName
dim index as integer = FindIndex(list, self)
if index >= 0 then
List.CellValueAt(index, 4) = "..."
end if
End EventHandler
Property List As WebListBox
End Class
Module UtilityModule
Function FindIndex(list as WebListBox, Service as NSNetServiceMBS) As integer
dim u as integer = list.RowCount-1
for i as integer = u downto 0
dim n as NSNetServiceMBS = list.RowTagAt(i)
if n<>nil and n.handle = Service.handle then
Return i
end if
next
End Function
End Module
End Project
See also:
The items on this page are in the following plugins: MBS MacFrameworks Plugin.
Feedback: Report problem or ask question.