Platforms to show: All Mac Windows Linux Cross-Platform

/Network/Bonjour/Bonjour


Required plugins for this example: MBS Network Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Network/Bonjour/Bonjour

This example is the version from Fri, 13th Oct 2016.

Project "Bonjour.xojo_binary_project"
Class Window1 Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control TabPanel1 Inherits TabPanel
ControlInstance TabPanel1 Inherits TabPanel
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control Rservicename Inherits TextField
ControlInstance Rservicename Inherits TextField
End Control
Control Rservicetype Inherits TextField
ControlInstance Rservicetype Inherits TextField
End Control
Control Rdomain Inherits TextField
ControlInstance Rdomain Inherits TextField
End Control
Control Rport Inherits TextField
ControlInstance Rport Inherits TextField
End Control
Control TypelistButton Inherits PushButton
ControlInstance TypelistButton Inherits PushButton
EventHandler Sub Action() // URL from Apple's docs showurl "http://www.iana.org/assignments/port-numbers" End EventHandler
End Control
Control RegisterButton Inherits PushButton
ControlInstance RegisterButton Inherits PushButton
EventHandler Sub Action() r = new MyBonjourRegisterMBS if r.Register(0, MyBonjourBrowseMBS.kInterfaceIndexAny, Rservicename.text, Rservicetype.text, Rdomain.text, "", val(Rport.text),"") then MsgBox "Registering started successfull." else MsgBox "Registering failed." end if End EventHandler
End Control
Control StaticText7 Inherits Label
ControlInstance StaticText7 Inherits Label
End Control
Control StaticText8 Inherits Label
ControlInstance StaticText8 Inherits Label
End Control
Control StaticText9 Inherits Label
ControlInstance StaticText9 Inherits Label
End Control
Control lServicename Inherits TextField
ControlInstance lServicename Inherits TextField
End Control
Control lservicetype Inherits TextField
ControlInstance lservicetype Inherits TextField
End Control
Control ldomain Inherits TextField
ControlInstance ldomain Inherits TextField
End Control
Control ResolveButton Inherits PushButton
ControlInstance ResolveButton Inherits PushButton
EventHandler Sub Action() l=new MyBonjourResolveMBS if l.Resolve(0, lServicename.text,lservicetype.text, ldomain.text) then MsgBox "Resolve started successfull." else MsgBox "Resolve failed." end if End EventHandler
End Control
Control StaticText10 Inherits Label
ControlInstance StaticText10 Inherits Label
End Control
Control StaticText11 Inherits Label
ControlInstance StaticText11 Inherits Label
End Control
Control bServicename Inherits TextField
ControlInstance bServicename Inherits TextField
End Control
Control bdomain Inherits TextField
ControlInstance bdomain Inherits TextField
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() b=new MyBonjourBrowseMBS if b.Browse(0,bServicename.text,bdomain.text) then MsgBox "Browse started successfull." else MsgBox "Browse failed." end if End EventHandler
End Control
Control RadioEnumerate Inherits RadioButton
ControlInstance RadioEnumerate(0) Inherits RadioButton
ControlInstance RadioEnumerate(1) Inherits RadioButton
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim n as integer if RadioEnumerate(0).Value then n=MyBonjourDomainEnumerationMBS.kFlagsRegistrationDomains // recommended registration domains else n=MyBonjourDomainEnumerationMBS.kFlagsBrowseDomains // browsing domains end if e=new MyBonjourDomainEnumerationMBS if e.EnumerateDomains(n,0) then MsgBox "Enumerating started successfull." else MsgBox "Enumerating failed." end if End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() r=nil End EventHandler
End Control
EventHandler Sub Close() b = nil e = nil r = nil l = nil End EventHandler
EventHandler Sub Open() if MyBonjourBrowseMBS.Available then write "Bonjour is available." else msgBox "No Bonjour found!" quit end if End EventHandler
Sub write(s as string) listBox1.addrow s listBox1.scrollPosition=listBox1.listcount End Sub
Property b As myBonjourbrowseMBS
Property e As myBonjourdomainEnumerationMBS
Property l As myBonjourResolveMBS
Property r As myBonjourregisterMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class MyBonjourBrowseMBS Inherits DNSServiceBrowseMBS
EventHandler Sub ServiceBrowse(Flags as integer, InterfaceIndex as integer, ErrorCode as integer, ServiceName as string, RegType as string, Domain as string) window1.write "ServiceBrowse event." Window1.write " Name: "+ServiceName Window1.write " Type: "+RegType Window1.write " Domain: "+domain Window1.write " Flags: "+str(flags) End EventHandler
End Class
Class MyBonjourDomainEnumerationMBS Inherits DNSServiceDomainEnumerationMBS
EventHandler Sub ServiceDomainEnumeration(flags as integer, interfaceIndex as integer, errorcode as integer, Domain as string) Window1.write "ServiceDomainEnumeration event." Window1.write " Domain: "+domain Window1.write " Flags: "+str(flags) End EventHandler
End Class
Class MyBonjourResolveMBS Inherits DNSServiceResolveMBS
EventHandler Sub ServiceResolve(flags as integer, InterfaceIndex as integer, ErrorCode as integer, Fullname as string, Hosttarget as string, Port as integer, TxtRecord as string) window1.write "ServiceResolve event." window1.write " Port: "+str(port) window1.write " Host: "+Hosttarget dim a1 as new MyDNSServiceAddrInfoMBS call a1.AddrInfo(InterfaceIndex, a1.kProtocolIPv4, Hosttarget) queries.Append a1 dim a2 as new MyDNSServiceAddrInfoMBS call a2.AddrInfo(InterfaceIndex, a2.kProtocolIPv6, Hosttarget) queries.Append a2 End EventHandler
Property queries() As MyDNSServiceAddrInfoMBS
End Class
Class MyBonjourRegisterMBS Inherits DNSServiceRegisterMBS
EventHandler Sub ServiceRegistration(flags as integer, errorcode as integer, Name as string, RegType as string, Domain as string) window1.write "ServiceRegistration event." window1.write " Errorcode: "+str(errorcode) End EventHandler
End Class
Class App Inherits Application
End Class
Class MyDNSServiceAddrInfoMBS Inherits DNSServiceAddrInfoMBS
EventHandler Sub ServiceAddrInfo(Flags as integer, InterfaceIndex as integer, ErrorCode as integer, AddressFamily as Integer, IP as string, SockAddr as MemoryBlock, HostName as string, ttl as Integer) window1.write "ServiceAddrInfo event." window1.write " IP: "+IP window1.write " AddressFamily: "+str(AddressFamily) window1.write " TTL: "+str(ttl) End EventHandler
End Class
End Project

See also:

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


The biggest plugin in space...