AutoDiscovery

From Xojo Documentation
Jump to: navigation, search

Class (inherits from EasyUDPSocket)

AutoDiscovery uses the EasyUDPSocket class to automatically discover other Xojo applications on the network.


Events
DataAvailable MemberJoined SendComplete
Error MemberLeft
Error ReceivedMessage


Properties
BroadcastAddress ReadOnlyProperty.png LocalAddress ReadOnlyProperty.png Port
Handle ReadOnlyProperty.png NetworkInterface RouterHops
IsConnected ReadOnlyProperty.png PacketsAvailable ReadOnlyProperty.png SendToSelf
LastErrorCode ReadOnlyProperty.png PacketsLeftToSend ReadOnlyProperty.png


Methods
Bind Poll SendMessageToIndividual
Close Purge Unregister
Connect Read UpdateMemberList
GetMemberList Register Write
JoinMulticastGroup SendMessageToGroup Write
LeaveMulticastGroup SendMessageToGroup


Notes

The AutoDiscovery class lets you automatically discover other machines on the local network that are communicating using the EasyUDPSocket class. It does so by checking to see which other applications are using the same group name that you pass to the Register function of the EasyUDPSocket class. When a member joins (this includes your application when you first call the Register method), you will get a MemberJoined event with the IP address of the member that joined. When a member leaves, then you get a MemberLeft event with their IP as well. If you would like a list of the currently connected members, you can get an array of their IPs by calling the GetMemberList method. You can refresh the list by calling the UpdateMemberList method. It clears the internal list of connected members and re-queries the network for members.

The AutoDiscovery class is intended to make communication among network users as easy as possible. To do so, it uses of a proprietary protocol. Because of this, it is unable to discover other communications protocols that may also be running on the network, such as iChat. Use the generic classes such as TCPSocket, UDPSocket, HTTPSocket, and so forth.


Examples

Binding to any available port between 8192 and 65535 (Note: the other member of the group must then use the same port, so you need to find a way to communicate this port to the others):

Do
Me.Bind(Rnd * (65536 - 8192) + 8192)
Loop Until Me.LastErrorCode = 0


Registering as a group member. Everyone on the network who wants to join the group needs to use the same group name:

AutoDiscovery1.Register("MyGroup")
AutoDiscovery1.UpdateMemberList


Getting the member list and displaying it in a ListBox:

Dim s() As String
s = AutoDiscovery1.GetMemberList
For i As Integer =0 To Ubound(s)
ListBox1.AddRow(s(i))
Next


Leaving the group:

AutoDiscovery1.Unregister("MyGroup")

Sending a message to the group:

AutoDiscovery1.SendMessageToGroup(100, "Hello world")


Receiving a message using the ReceivedMessage event:

Sub ReceivedMessage (fromIP As String, command As Integer, data As String)
MsgBox(fromIP + " sent us " + Str(command) + ": " + Data)
End Sub

See Also

EasyUDPSocket, UDPSocket classes.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About