Platforms to show: All Mac Windows Linux Cross-Platform

/Network/Bonjour/Find computer


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/Find computer

This example is the version from Sat, 9th Feb 2018.

Project "Find computer.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
EventHandler Sub Open() StartBrowse "_ftp._tcp","FTP Server" StartBrowse "_afpovertcp._tcp","Apple File Sharing" StartBrowse "_nfs._tcp","Network File System" StartBrowse "_http._tcp","Webserver" StartBrowse "_printer._tcp","Printer" StartBrowse "_ichat._tcp","iChat (old)" StartBrowse "_presence._tcp","iChat" StartBrowse "_daap._tcp","iTunes" StartBrowse "_dpap._tcp","iPhoto" StartBrowse "_ipp._tcp","Intenet Printing Protocol" StartBrowse "_pdl-datastream._tcp","PDL Data Stream" StartBrowse "_distcc._tcp","XCode" StartBrowse "_xserveraid._tcp","XServe RAID" End EventHandler
Sub ClearAddrInfos() dim u as integer = UBound(addrinfos) for i as integer = u downto 0 if addrinfos(i).done then addrinfos.Remove i end if next End Sub
Sub ClearLookups() dim u as integer = UBound(lookup) for i as integer = u downto 0 if lookup(i).done then lookup.Remove i end if next End Sub
Sub StartAddrInfo(name as string, type as string, domain as string, reason as string, hostname as string, port as integer) dim b as new MyAddrInfo ClearAddrInfos if b.AddrInfo(0, b.kProtocolIPv4, hostname) then b.Reason = reason b.name = name b.port = port addrinfos.Append b end if End Sub
Sub StartBrowse(typ as string, reason as string) dim b as new MyBrowser if b.Browse(0,typ,"") then b.Reason=reason browser.Append b else List.AddRow "Failed to init browser for "+typ end if End Sub
Sub StartLookup(name as string, type as string, domain as string, reason as string) dim b as new MyLookup ClearLookups if b.Resolve(0,name,type,domain) then b.Reason = reason b.domain = domain b.name = name b.type = type lookup.Append b end if End Sub
Property addrinfos() As MyAddrInfo
Property Protected browser() As MyBrowser
Property Protected lookup() As MyLookup
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class MyBrowser Inherits DNSServiceBrowseMBS
EventHandler Sub ServiceBrowse(Flags as integer, InterfaceIndex as integer, ErrorCode as integer, ServiceName as string, RegType as string, Domain as string) const kDNSServiceFlagsAdd=2 dim f as integer f=BitwiseAnd(Flags, kDNSServiceFlagsAdd) if f<>0 then // added Window1.StartLookup ServiceName,RegType,domain,reason else // removed Window1.List.AddRow ServiceName Window1.List.Cell(Window1.List.LastIndex,1)="gone" Window1.List.Cell(Window1.List.LastIndex,2)="" Window1.List.Cell(Window1.List.LastIndex,3)=reason end if End EventHandler
Property reason As string
End Class
Class MyLookup 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) if not done then window1.StartAddrInfo name, type, domain, reason, Hosttarget, port end if done = (BitwiseAnd(flags, me.kFlagsMoreComing) = 0) End EventHandler
Property domain As string
Property done As boolean
Property name As string
Property reason As string
Property type As string
End Class
Class MyAddrInfo 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) if not IPs.HasKey(IP) then // avoid duplicates dim l as listbox = Window1.List l.addrow name l.Cell(l.LastIndex,1)=IP+":"+str(port) l.Cell(l.LastIndex,2)=HostName l.Cell(l.LastIndex,3)=reason IPS.Value(IP) = nil end if done = (BitwiseAnd(flags, me.kFlagsMoreComing) = 0) End EventHandler
Sub Constructor() IPs = new Dictionary End Sub
Property IPs As Dictionary
Property done As Boolean
Property name As string
Property port As Integer
Property reason As string
End Class
End Project

See also:

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


The biggest plugin in space...