Platforms to show: All Mac Windows Linux Cross-Platform

/Linux/Avahi Browse
Function:
Required plugins for this example: MBS Linux Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Linux/Avahi Browse
This example is the version from Wed, 25th Sep 2012.
Project "Avahi Browse.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() if MyClient.available = false then MsgBox "Please run on Linux with avahi installed." quit end if client = new MyClient log "HostName: "+Client.HostName log "Domain: "+Client.DomainName log "Version: "+Client.Version // for the list of domains we find domains = new Dictionary // for the list of types we find types = new Dictionary // for the browsers we run Browsers = new Dictionary // for the resolvers we run Resolvers = new Dictionary // look for types typebrowser = new MyTypeBrowser(client) call typebrowser.BrowseTypes(typebrowser.kInterfaceAny, typebrowser.kProtocolAny) End EventHandler
Sub Browse() for each domain as string in domains.Keys for each type as string in types.keys dim key as string = type+domain if Browsers.HasKey(key) then // already handled else dim b as new MyBrowser(client) if b.Browse(b.kInterfaceAny, b.kProtocolAny, type, domain) then Browsers.Value(key) = b end if end if next next End Sub
Property Browsers As Dictionary
Property Client As MyClient
Property Domains As Dictionary
Property Resolvers As Dictionary
Property Types As Dictionary
Property typebrowser As MyTypeBrowser
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() // speedup the plugin AvahiClientMBS.Poll End EventHandler
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyClient Inherits AvahiClientMBS
EventHandler Sub Failure(error as string, errorcode as integer) Log "Client Failure: "+error End EventHandler
EventHandler Sub Running() log "Running..." End EventHandler
End Class
Class MyBrowser Inherits AvahiBrowserMBS
EventHandler Sub Failure(error as string, errorcode as integer) Log "Browser Failure: "+error End EventHandler
EventHandler Sub ServiceFound(InterfaceIndex as integer, protocol as Integer, name as string, type as string, domain as string, flags as integer) Log "Found Service "+name+" of type "+type+" ("+description+") at domain "+domain dim key as string = name+type+domain if app.Resolvers.HasKey(key) then // already running else dim r as new MyResolver(Client) if r.Resolve(InterfaceIndex, protocol, name, type, domain, 0) then app.Resolvers.Value(key) = r end if end if End EventHandler
EventHandler Sub ServiceRemoved(InterfaceIndex as integer, protocol as Integer, name as string, type as string, domain as string, flags as integer) Log "Lost Service "+name+" of type "+type+" ("+description+") at domain "+domain // here you could stop resolvers started in the ServiceFound events End EventHandler
Property description As string
End Class
Class MyResolver Inherits AvahiResolverMBS
EventHandler Sub Failure(error as string, errorcode as integer) Log "Resolver Failure: "+error End EventHandler
EventHandler Sub Found(interfaceIndex as integer, Protocol as Integer, name as string, type as string, domain as string, hostname as string, port as integer, address as string, txt as string, flags as integer) Log "Found Address "+address+":"+str(port)+" for "+name End EventHandler
End Class
Module Module1
Sub Log(s as string) MainWindow.List.AddRow str(ticks), s MainWindow.List.ScrollPosition = MainWindow.List.ListCount End Sub
End Module
Class MyTypeBrowser Inherits AvahiTypeBrowserMBS
EventHandler Sub Failure(error as string, errorcode as integer) Log "Browser Failure: "+error End EventHandler
EventHandler Sub TypeFound(InterfaceIndex as integer, protocol as Integer, type as string, domain as string, flags as integer) Log "Found Type "+type+" ("+description+") at domain "+domain app.domains.Value(domain) = domain app.types.Value(type) = type app.Browse End EventHandler
EventHandler Sub TypeRemoved(InterfaceIndex as integer, protocol as Integer, type as string, domain as string, flags as integer) Log "Lost Type "+type+" ("+description+") at domain "+domain // here you could stop resolvers started in the ServiceFound events End EventHandler
Property description As string
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Linux Plugin.

The biggest plugin in space...




Links
MBS FileMaker Plugins

Start Chat