Platforms to show: All Mac Windows Linux Cross-Platform

/MacOSX/Bonjour/Bonjour Console
Feedback.

Function:
You find this example project in your Plugins Download as a Realbasic project file within the examples folder: /MacOSX/Bonjour/Bonjour Console
This example is the version from Fri, 25th Feb 2010.
Notes: Last modified: Fri, 25th Feb 2010
Class App
Inherits ConsoleApplication
// Properties
Protected Dim b As MyRendezvousBrowseMBS
Protected Dim r As MyRendezvousRegisterMBS
Protected Dim l As MyRendezvousLookupMBS

// Event implementations
Function Run(args() as String) As Integer
print "This application does registering a service, browse and lookup this service."
print "Press control-C to quit."

b=new MyRendezvousBrowseMBS
r=new MyRendezvousRegisterMBS
l=new MyRendezvousLookupMBS

if b.Available then
print "Bonjour is available."
else
print "No Bonjour found!"
Return 1
end if

Register

// wait 2 seconds and give sockets, threads and timers time
for i as integer=0 to 20
DelayMBS 0.1
DoEvents
next

Browse

// give sockets, threads and timers time
do
DelayMBS 0.1
DoEvents
loop

End Function

// Methods
Protected Sub Register()
if r.Register(0,0,"MyService","_echo._tcp.", "local.", "", 1111, "") then
print "Registering started successfull."
else
print "Registering failed."
end if

End Sub
Protected Sub Browse()
if b.Browse(0,"_echo._tcp","local.") then
print "Browse started successfull."
else
print "Browse failed."
end if
End Sub
Sub Lookup(ServiceName as string, domain as string)
if app.l.Lookup(0, ServiceName,"_echo._tcp.", domain) then
print "Lookup started successfull."
else
print "Lookup failed."
end if
End Sub
End Class

Class MyRendezvousBrowseMBS
Inherits Object
// Event implementations
Sub ServiceBrowse(Flags as integer, InterfaceIndex as integer, ErrorCode as integer, ServiceName as string, RegType as string, Domain as string)
print "ServiceBrowse event."
print " Service name: "+ServiceName
print " Interface index: "+str(InterfaceIndex)
print " Registration Type: "+RegType
print " Domain: "+domain
print " Flags: "+str(flags)

app.lookup ServiceName, domain

End Sub
End Class

Class MyRendezvousLookupMBS
Inherits Object
// Event implementations
Sub ServiceLookup(flags as integer, InterfaceIndex as integer, ErrorCode as integer, Fullname as string, Hosttarget as string, Port as integer, TxtRecord as string)
print "ServiceLookup event."
print " Error code: "+str(ErrorCode)
print " IP: "+DNSNameToAddressMBS(Hosttarget)
print " Port: "+str(port)
print " Interface index: "+str(InterfaceIndex)
print " Host target: "+Hosttarget
print " Fullname: "+Fullname

End Sub
End Class

Class MyRendezvousRegisterMBS
Inherits Object
// Event implementations
Sub ServiceRegistration(flags as integer, errorcode as integer, Name as string, RegType as string, Domain as string)
print "ServiceRegistration event."
print " Errorcode: "+str(errorcode)
End Sub
End Class


See also:




Links
MBS Realbasic tutorial videos - Nachhilfe in Kruft