Platforms to show: All Mac Windows Linux Cross-Platform
/MacFrameworks/NSNetService/Bonjour Browser Web1
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/NSNetService/Bonjour Browser Web1
This example is the version from Sat, 19th Feb 2021.
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/NSNetService/Bonjour Browser Web1
This example is the version from Sat, 19th Feb 2021.
Project "Bonjour Browser Web1.xojo_binary_project"
Class App Inherits WebApplication
EventHandler Sub Open(args() as String)
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 EventHandler
Property EventTimer As Timer
Property Protected testService As NSNetServiceMBS
End Class
Class Session Inherits WebSession
Const ErrorDialogCancel = "Do Not Send"
Const ErrorDialogMessage = "This application has encountered an error and cannot continue."
Const ErrorDialogQuestion = "Please describe what you were doing right before the error occurred:"
Const ErrorDialogSubmit = "Send"
Const ErrorThankYou = "Thank You"
Const ErrorThankYouMessage = "Your feedback helps us make improvements."
Const NoJavascriptInstructions = "To turn Javascript on, please refer to your browser settings window."
Const NoJavascriptMessage = "Javascript must be enabled to access this page."
End Class
Class MainPage Inherits WebPage
Control List Inherits WebListBox
ControlInstance List Inherits WebListBox
End Control
EventHandler Sub Open()
#if TargetMachO then
// run on main thread, so events get delivered
xojo.core.timer.CallLater 0, WeakAddressOf searchForServices
#else
MsgBox "This example requires OS X."
#endif
End EventHandler
Sub searchForServices()
// search for types
searchForServicesOfType "_test._tcp."
searchForServicesOfType "_smb._tcp."
searchForServicesOfType "_afpovertcp._tcp."
searchForServicesOfType "_printer._tcp."
searchForServicesOfType "_http._tcp."
searchForServicesOfType "_presence._tcp."
searchForServicesOfType "_whats-my-name._tcp."
searchForServicesOfType "_rfb._tcp."
End Sub
Protected Sub searchForServicesOfType(type as text)
dim m as new ServiceBrowser
m.list = List
// search for domains
m.searchForServicesOfType type
browsers.Append m
End Sub
Property Protected browsers() As ServiceBrowser
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.RowTag(list.LastIndex) = 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.RemoveRow 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.Cell(index, 3) = "failed"
List.Cell(index, 4) = ""
end if
End EventHandler
EventHandler Sub DidResolveAddress()
System.DebugLog CurrentMethodName
dim index as integer = FindIndex(list, self)
if index >= 0 then
List.Cell(index, 2) = me.hostName
List.Cell(index, 3) = me.addressIPv4
List.Cell(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.Cell(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.RowTag(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.