Class

# AutoDiscovery

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

<span class="title-ref">AutoDiscovery</span> uses the `EasyUDPSocket</api/networking/easyudpsocket>` class to automatically discover other Xojo applications on the network.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                                 | Type                                                 | Read-Only | Shared |
|------------------------------------------------------|------------------------------------------------------|-----------|--------|
| `BroadcastAddress<autodiscovery.broadcastaddress>`   | `String</api/data_types/string>`                     | ✓         |        |
| `Handle<autodiscovery.handle>`                       | `Integer</api/data_types/integer>`                   | ✓         |        |
| `IsConnected<autodiscovery.isconnected>`             | `Boolean</api/data_types/boolean>`                   | ✓         |        |
| `LocalAddress<autodiscovery.localaddress>`           | `String</api/data_types/string>`                     | ✓         |        |
| `NetworkInterface<autodiscovery.networkinterface>`   | `NetworkInterface</api/networking/networkinterface>` |           |        |
| `PacketsAvailable<autodiscovery.packetsavailable>`   | `Integer</api/data_types/integer>`                   | ✓         |        |
| `PacketsLeftToSend<autodiscovery.packetslefttosend>` | `Integer</api/data_types/integer>`                   | ✓         |        |
| `Port<autodiscovery.port>`                           | `Integer</api/data_types/integer>`                   |           |        |
| `RouterHops<autodiscovery.routerhops>`               | `Integer</api/data_types/integer>`                   |           |        |
| `SendToSelf<autodiscovery.sendtoself>`               | `Boolean</api/data_types/boolean>`                   |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                             | Parameters                                                                                                                                   | Returns                              | Shared |
|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|--------|
| `Bind<autodiscovery.bind>`                                       | port As `Integer</api/data_types/integer>`                                                                                                   |                                      |        |
| `Close<autodiscovery.close>`                                     |                                                                                                                                              |                                      |        |
| `Connect<autodiscovery.connect>`                                 |                                                                                                                                              |                                      |        |
| `GetMemberList<autodiscovery.getmemberlist>`                     |                                                                                                                                              | `String()</api/data_types/string>`   |        |
| `JoinMulticastGroup<autodiscovery.joinmulticastgroup>`           | Group As `String</api/data_types/string>`                                                                                                    | `Boolean</api/data_types/boolean>`   |        |
| `LeaveMulticastGroup<autodiscovery.leavemulticastgroup>`         | Group As `String</api/data_types/string>`                                                                                                    |                                      |        |
| `Poll<autodiscovery.poll>`                                       |                                                                                                                                              |                                      |        |
| `Purge<autodiscovery.purge>`                                     |                                                                                                                                              |                                      |        |
| `Read<autodiscovery.read>`                                       | enc As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>`                                                       | `Datagram</api/networking/datagram>` |        |
| `Register<autodiscovery.register>`                               | groupName As `String</api/data_types/string>`                                                                                                |                                      |        |
| `SendMessageToGroup<autodiscovery.sendmessagetogroup>`           | command As `Int32</api/data_types/additional_types/int32>`, data As `String</api/data_types/string>`                                         |                                      |        |
| `SendMessageToIndividual<autodiscovery.sendmessagetoindividual>` | ip As `String</api/data_types/string>`, command As `Int32</api/data_types/additional_types/int32>`, data As `String</api/data_types/string>` |                                      |        |
| `Unregister<autodiscovery.unregister>`                           | groupName As `String</api/data_types/string>`                                                                                                |                                      |        |
| `UpdateMemberList<autodiscovery.updatememberlist>`               |                                                                                                                                              |                                      |        |
| `WaitForMessage<autodiscovery.waitformessage>`                   | command As `Int32</api/data_types/additional_types/int32>`, fromIP As `String</api/data_types/string>`                                       | `String</api/data_types/string>`     |        |
| `Write<autodiscovery.write>`                                     | data As `Datagram</api/networking/datagram>`                                                                                                 |                                      |        |
|                                                                  | ip As `String</api/data_types/string>`, data As `String</api/data_types/string>`                                                             |                                      |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                             | Parameters                                                                                                                          | Returns |
|--------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|---------|
| `DataAvailable<autodiscovery.dataavailable>`     |                                                                                                                                     |         |
| `Error<autodiscovery.error>`                     | code As `Integer</api/data_types/integer>`                                                                                          |         |
| `MemberJoined<autodiscovery.memberjoined>`       | IPAddress As `String</api/data_types/string>`                                                                                       |         |
| `MemberLeft<autodiscovery.memberleft>`           | IPAddress As `String</api/data_types/string>`                                                                                       |         |
| `ReceivedMessage<autodiscovery.receivedmessage>` | FromIP As `String</api/data_types/string>`, Command As `Integer</api/data_types/integer>`, Data As `String</api/data_types/string>` |         |
| `SendComplete<autodiscovery.sendcomplete>`       | UserAborted As `Boolean</api/data_types/boolean>`                                                                                   |         |

## Property descriptions

<div id="autodiscovery.broadcastaddress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.BroadcastAddress

**BroadcastAddress** As `String</api/data_types/string>`

> The machine's broadcast address.
>
> This property is read-only.
>
> You can specify this address when you call the `Write<udpsocket.write>` method and the data will be broadcast across the network, but you will not receive the data you sent back.
>
> This example uses the BroadcastAddress to get the address of the group.
>
> ``` xojo
> AutoDiscovery1.Write(AutoDiscovery1.BroadcastAddress, "Hello World")
> ```

<div id="autodiscovery.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Handle

**Handle** As `Integer</api/data_types/integer>`

> This is the socket's internal descriptor and it can be used with `Declare</api/language/declare>` statements.
>
> This property is read-only.
>
> - On Windows, Handle is a Socket, suitable for use in `Declares</api/language/declare>` on Windows.
> - On macOS and Linux, Handle is a UNIX socket descriptor.
>
> The descriptor is platform-specific. If *Handle* is less than zero, the descriptor is not available.

<div id="autodiscovery.isconnected">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.IsConnected

**IsConnected** As `Boolean</api/data_types/boolean>`

> Indicates whether the socket is currently connected.
>
> This property is read-only.
>
> For `TCPSockets</api/networking/tcpsocket>`, a connection means you can send and receive data and are connected to a remote machine. For `UDPSockets</api/networking/udpsocket>`, this means that you are bound to the port and are able to send, receive, join or leave multicast groups, or set socket options.
>
> ``` xojo
> If AutoDiscovery1.IsConnected Then
>   ' proceed using the connection
> Else
>   MessageBox("Connection failed!")
> End If
> ```

<div id="autodiscovery.localaddress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.LocalAddress

**LocalAddress** As `String</api/data_types/string>`

> The local IP address of the computer.
>
> This property is read-only.
>
> ``` xojo
> Var localIP As String = AutoDiscovery1.LocalAddress
> ```

<div id="autodiscovery.networkinterface">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.NetworkInterface

**NetworkInterface** As `NetworkInterface</api/networking/networkinterface>`

> Specifies which network interface the socket should use when binding.
>
> You can get the network interface(s) of the user's computer by calling the `GetNetworkInterface<system.networkinterface>` method of the `System</api/os/system>` module.
>
> Leaving this property set to `Nil</api/language/nil>` will use the currently selected interface. In the case of `UDPSockets</api/networking/udpsocket>`, if you assign a non-`Nil</api/language/nil>` value, the socket may not be able to receive broadcast messages. The behavior is OS-dependent; it appears to work on Windows but not on other supported operating systems. If you wish to send broadcast packets out, then you should not bind to a specific interface because the behavior is undefined.
>
> This example specifies that the <span class="title-ref">AutoDiscovery</span> will use the first Network Interface on the user's computer.
>
> ``` xojo
> AutoDiscovery1.NetworkInterface = System.NetworkInterface(0)
> ```

<div id="autodiscovery.packetsavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.PacketsAvailable

**PacketsAvailable** As `Integer</api/data_types/integer>`

> The number of packets available in the internal receive buffer.
>
> This property is read-only.

<div id="autodiscovery.packetslefttosend">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.PacketsLeftToSend

**PacketsLeftToSend** As `Integer</api/data_types/integer>`

> The number of packets left in the queue to send.
>
> This property is read-only.
>
> This enables you to create a synchronous socket without needing to subclass the **UDPSocket**.

<div id="autodiscovery.port">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Port

**Port** As `Integer</api/data_types/integer>`

> The port to bind on or connect to.
>
> On most operating systems, attempting to bind to a port less than 1024 causes a `Error<socketcore.error>` event to fire with an error number 107 unless the application is running with administrative permissions. This is due to security features built into the underlying OS.
>
> You need to set the port property explicitly before any call to Listen or Connect as the Port property will be modified to reflect what the actual bound port is during the various stages of operation.
>
> For instance, if you listen on port 8080 and a connection comes in, you can check the Port property to ensure that you're still listening on port 8080 (that the port hasn't been hijacked). Or, if you connect to a socket on port 8080, once the connection occurs, you can check to see what port the OS has bound you to. This will be a random-seeming port number.
>
> This trick can be very useful when you do things like Listen on port 0. In that case, the OS will pick a port for you and listen on it. Then you can check the Port property to see which port the OS picked. This functionality is used for various protocols, such as FTP.
>
> This example sets the Port to 8080.
>
> ``` xojo
> AutoDiscovery1.Port = 8080
> ```

<div id="autodiscovery.routerhops">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.RouterHops

**RouterHops** As `Integer</api/data_types/integer>`

> Specifies how many router hops the data sent out can make.
>
> Multicasting has some extra features that make it an even more powerful utility for network applications. If you wish to receive the data you sent out with a multicast send, you can set the `SendToSelf<udpsocket.sendtoself>` property (also known as *loopback*) of the `UDPSocket</api/networking/udpsocket>`. If it is set to `True</api/language/true>`, then when you do a send (to a multicast group) you will get that data back. You can also set the number of router hops a multicast datagram will take (This is also known as the Time To Live (or TTL). When your `Datagram</api/networking/datagram>` gets sent out, it runs through a series of routers on the way to its destinations. Every time the `Datagram</api/networking/datagram>` hits a router, its `RouterHops<udpsocket.routerhops>` property gets decremented. When that number reaches zero, the `Datagram</api/networking/datagram>` is destroyed. This means you can control who gets your datagrams with a lot more precision. There are some “best guesses” as to what the value of `RouterHops<udpsocket.routerhops>` should be.
>
> | Value | Description    |
> |-------|----------------|
> | 0     | Same host      |
> | 1     | Same subnet    |
> | 32    | Same site      |
> | 64    | Same region    |
> | 128   | Same continent |
> | 255   | Unrestricted   |
>
> Note that if your `Datagram</api/networking/datagram>` runs through a router that does not support multicasting, it is killed immediately.
>
> ``` xojo
> AutoDiscovery1.RouterHops = 32
> ```

<div id="autodiscovery.sendtoself">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.SendToSelf

**SendToSelf** As `Boolean</api/data_types/boolean>`

> Specifies whether the data you send out will be sent to yourself as well.
>
> This is also known as loopback. This property applies only to multicast sends.
>
> Setting the SendToSelf property to `True</api/language/true>` may not work on all versions of Windows. MSDN states that the SendToSelf property on NT 4 cannot be turned off. A multicasting socket will always receive the data it sends out.
>
> ``` xojo
> AutoDiscovery1.SendToSelf = True
> ```

## Method descriptions

<div id="autodiscovery.bind">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Bind

**Bind**(port As `Integer</api/data_types/integer>`)

> Binds the socket to the specified *port*.
>
> This example binds the socket 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):
>
> ``` xojo
> Var success As Boolean
>
> Do
>   success = True
>   Try
>     Me.Bind (Rnd * (65536 - 8192) + 8192)
>   Catch error As RuntimeException
>     success = False
>   End Try
> Loop Until success
> ```

<div id="autodiscovery.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Close

**Close**

> Closes the socket's connection, closes any connections the socket may have, and resets the socket.
>
> The only information that is retained after calling Close is the socket's port, address (in the case of `TCPSockets</api/networking/tcpsocket>`), and data left in the socket's receive buffer. All other information is discarded.
>
> This example closes the `EasyTCPSockets</api/networking/easytcpsocket>` that were open. The sockets were added to the main window.
>
> ``` xojo
> Connector.Close
> Listener.Close
> ```

<div id="autodiscovery.connect">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Connect

**Connect**

> Attempts to connect.
>
> For `TCPSockets</api/networking/tcpsocket>`, the address and port properties must be set. For `UDPSockets</api/networking/udpsocket>`, the port property must be set. The Connect method binds a socket to a port. After calling Connect, the Port property will report the actual port you are bound to.

<div id="autodiscovery.getmemberlist">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.GetMemberList

**GetMemberList** As `String()</api/data_types/string>`

> Returns a `String</api/data_types/string>` array of IP addresses belonging to the list of machines on the network who are in the group.

<div id="autodiscovery.joinmulticastgroup">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.JoinMulticastGroup

**JoinMulticastGroup**(Group As `String</api/data_types/string>`) As `Boolean</api/data_types/boolean>`

> Joins the specified multicast *Group*. Returns `True</api/language/true>` if the *Group* was successfully joined, `False</api/language/false>` if not.
>
> ``` xojo
> If AutoDiscovery1.JoinMulticastGroup(TextField5.Text) Then
>   MessageBox("Joined!")
> End If
> ```

<div id="autodiscovery.leavemulticastgroup">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.LeaveMulticastGroup

**LeaveMulticastGroup**(Group As `String</api/data_types/string>`)

> Leaves the specified multicast *Group*. The `TextField</api/user_interface/desktop/desktoptextfield>` contains the name of the *Group*.
>
> ``` xojo
> AutoDiscovery1.LeaveMulticastGroup(TextField5.Text)
> ```

<div id="autodiscovery.poll">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Poll

**Poll**

> Polls the socket manually, which allows a socket to be used synchronously.
>
> The `EasyTCPSocket</api/networking/easytcpsocket>` "Listener" has been added to the window.
>
> ``` xojo
> Listener.Poll
> ```

<div id="autodiscovery.purge">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Purge

**Purge**

> Removes all data from the socket's internal receive buffer. It does not affect the socket's internal send buffer.
>
> ``` xojo
> Listener.Purge
> ```

<div id="autodiscovery.read">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Read

**Read**(enc As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>`) As `Datagram</api/networking/datagram>`

> Returns a `Datagram</api/networking/datagram>` from the internal receive buffer.
>
> The address property of the `Datagram</api/networking/datagram>` is the remote address from which the data was sent. The optional *enc* parameter enables you to specify the text encoding of the data to be returned. Use the `Encodings</api/text/encoding_text/encodings>` module to specify a text encoding.

<div id="autodiscovery.register">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Register

**Register**(groupName As `String</api/data_types/string>`)

> Registers *groupName* as an identifier for messages sent by SendMessageToGroup.
>
> *groupName* can be any string, which will be mapped it to a valid Class D IP address. Class D IP addresses are in the range: \[224.0.0.0 to 239.255.255.255\]. For example, you can call Register("My Cool App"), and it will be hashed to a valid Class D IP address. However, if you use a valid Class D IP address, it will use that without modifications.
>
> This example registers the user as a group member and updates the list. Everyone on the network who wants to join the group needs to use the same group name:
>
> ``` xojo
> AutoDiscovery1.Register("MyGroup")
> AutoDiscovery1.UpdateMemberList
> ```

<div id="autodiscovery.sendmessagetogroup">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.SendMessageToGroup

**SendMessageToGroup**(command As `Int32</api/data_types/additional_types/int32>`, data As `String</api/data_types/string>`)

> Sends the message consisting of *command* and *data* to the group.
>
> Effective with 2017r3, the *command* parameter is Int32 instead of Integer to prevent incorrect behavior in 64-bit apps.
>
> In order for this method to work you must have first registered a group (using the `Register<easyudpsocket.register>` method).

<div id="autodiscovery.sendmessagetoindividual">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.SendMessageToIndividual

**SendMessageToIndividual**(ip As `String</api/data_types/string>`, command As `Int32</api/data_types/additional_types/int32>`, data As `String</api/data_types/string>`)

> Sends a message consisting of *command* and *data* to the machine having the IP address specified by *ip*.
>
> Effective with 2017r3, the *command* parameter is `Int32</api/data_types/additional_types/int32>` instead of Integer to prevent incorrect behavior in 64-bit apps.
>
> The text encoding is not sent to the other application. So if you want to preserve text encoding, you should use `ConvertEncoding</api/text/encoding_text/convertencoding>` to e.g. UTF-8 before sending the string and use `DefineEncoding</api/text/encoding_text/defineencoding>` when you receive a message to restore the text encoding.

<div id="autodiscovery.unregister">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Unregister

**Unregister**(groupName As `String</api/data_types/string>`)

> Unregisters the *groupName* passed.

<div id="autodiscovery.updatememberlist">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.UpdateMemberList

**UpdateMemberList**

> Clears the internal list of connected members and queries the network for all members of the current group.
>
> This code registers as a group member and updates the list. Everyone on the network who wants to join the group needs to use the same group name:
>
> ``` xojo
> AutoDiscovery1.Register("MyGroup")
> AutoDiscovery1.UpdateMemberList
> ```

<div id="autodiscovery.waitformessage">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.WaitForMessage

**WaitForMessage**(command As `Int32</api/data_types/additional_types/int32>`, fromIP As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Waits for a message from the *fromIP* addresss identified by the value of *command*.
>
> Returns a `String</api/data_types/string>`, containing the message text.
>
> The *command* parameter can be used as a code to identify the type of data that is sent. For example, you could send a command ID of 100 to mean that the string data is actually a memory block containing a `FolderItem</api/files/folderitem>`. Or, you could define ID 101 as the username of a remote application. This message mode is enforced on you in that you cannot use an arbitrary Write command. If you'd like to send arbitrary data, then you can make up a miscellaneous command ID and send your arbitrary data.
>
> Command IDs less than 0 are reserved for internal use. When you are sending messages, you should not use a command ID less than 0, as it may very well cause issues with other classes.

<div id="autodiscovery.write">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Write

**Write**(data As `Datagram</api/networking/datagram>`)

> Constructs a `Datagram</api/networking/datagram>` and sends the data to the specified address.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Write

**Write**(ip As `String</api/data_types/string>`, data As `String</api/data_types/string>`)

> Constructs a `Datagram</api/networking/datagram>` and sends the *data* to the specified IP address *ip*.
>
> This example uses `BroadcastAddress<udpsocket.broadcastaddress>` to get the address of the group.
>
> ``` xojo
> AutoDiscovery1.Write(AutoDiscovery1.BroadcastAddress, "Hello World")
> ```

## Event descriptions

<div id="autodiscovery.dataavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.DataAvailable

**DataAvailable**

> Occurs when additional data has come into the internal receive buffer.

<div id="autodiscovery.error">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.Error

**Error**(code As `Integer</api/data_types/integer>`)

> Occurs when an error occurs with the socket.
>
> These error codes provide you with key information about your socket, and it is not advisable to ignore them.
>
> When an error occurs, the *code* parameter will likely contain one of the following error codes:
>
> | Error Code | Description                                                                                                             |
> |------------|-------------------------------------------------------------------------------------------------------------------------|
> | 0          | No error occurred.                                                                                                      |
> | 100        | There was an error opening and initializing the drivers.                                                                |
> | 101        | This error code is no longer used.                                                                                      |
> | 102        | This code means that you lost your connection.                                                                          |
> | 103        | The socket was unable to resolve the address that was specified.                                                        |
> | 104        | This error code is no longer used.                                                                                      |
> | 105        | The address is currently in use.                                                                                        |
> | 106        | This is an invalid state error, which means that the socket is not in the proper state to be doing a certain operation. |
> | 107        | This error means that the port you specified is invalid.                                                                |
> | 108        | This error indicates that your application has run out of memory.                                                       |
>
> These are not the only errors that are returned. For Windows, additional error codes are usually positive numbers in the range \[10004, 11004\]. For Windows error codes, see WinSock.h. MacOS and Linux use POSIX error codes. For a description of macOS and Linux error codes, see <http://www.ioplex.com/~miallen/errcmp.html>.
>
> e.g. error 64 is for "host is down".
>
> The following example in the Error event handler displays the error code.
>
> ``` xojo
> MessageBox(code.ToString)
> ```

<div id="autodiscovery.memberjoined">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.MemberJoined

**MemberJoined**(IPAddress As `String</api/data_types/string>`)

> A machine identified as *IPAddress* has joined.

<div id="autodiscovery.memberleft">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.MemberLeft

**MemberLeft**(IPAddress As `String</api/data_types/string>`)

> A machine identified as *IPAddress* has left.

<div id="autodiscovery.receivedmessage">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.ReceivedMessage

**ReceivedMessage**(FromIP As `String</api/data_types/string>`, Command As `Integer</api/data_types/integer>`, Data As `String</api/data_types/string>`)

> A new complete message, consisting of an identifying integer, *command*, and the text *data*, has been received from the computer with *FromIP* IP address.
>
> Effective with 2017r3, the *command* parameter is Int32 instead of Integer to prevent incorrect behavior in 64-bit apps.
>
> Both *fromIP* and *data* strings both have no encoding set. If you know the encoding, you should use `DefineEncoding</api/text/encoding_text/defineencoding>` to set it.

<div id="autodiscovery.sendcomplete">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

AutoDiscovery.SendComplete

**SendComplete**(UserAborted As `Boolean</api/data_types/boolean>`)

> Occurs when a send has completed.
>
> Use this to determine when all your data has been sent. *UserAborted* will be `True</api/language/true>` if the user aborted the send by returning `True</api/language/true>` from the SendProgress event. You can use this information to update different status variables or to inform user about the success or failure of the transfer. If the send was completed, this value is `False</api/language/false>`. UserAborted will always be `False</api/language/false>` for UDP sockets.

## Notes

The <span class="title-ref">AutoDiscovery</span> class lets you automatically discover other machines on the local network that are communicating using the `EasyUDPSocket</api/networking/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</api/networking/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 <span class="title-ref">AutoDiscovery</span> 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</api/networking/tcpsocket>`, `UDPSocket</api/networking/udpsocket>`, `URLConnection</api/networking/urlconnection>`, and so forth.

## Sample code

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):

``` xojo
Do
  AutoDiscovery1.Bind(Rnd * (65536 - 8192) + 8192)
Loop Until AutoDiscovery1.IsConnected
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

``` xojo
AutoDiscovery1.Register("MyGroup")
AutoDiscovery1.UpdateMemberList
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Getting the member list and displaying it in a `ListBox</api/user_interface/desktop/desktoplistbox>`:

``` xojo
For Each member As String In AutoDiscovery1.GetMemberList
  ListBox1.AddRow(member)
Next
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Leaving the group:

``` xojo
AutoDiscovery1.Unregister("MyGroup")
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sending a message to the group:

``` xojo
AutoDiscovery1.SendMessageToGroup(100, "Hello world")
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Receiving a message using the ReceivedMessage event:

``` xojo
Sub ReceivedMessage (fromIP As String, command As Integer, data As String)
  MessageBox(fromIP + " sent us " + command.ToString + ": " + Data)
End Sub
```

## Compatibility

|                       |                       |
|-----------------------|-----------------------|
| **Project Types**     | Console, Desktop, Web |
| **Operating Systems** | All                   |

<div class="seealso">

`EasyUDPSocket</api/networking/easyudpsocket>` parent class; `UDPSocket</api/networking/udpsocket>` classes.

</div>
