From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
Supports communication via the UDP protocol using unicasting, multicasting, or broadcasting. It provides a simple "wrapper" around the UDPSocket class that makes easier for beginners to get started with UDP networking.
Even though you have access to the Write and Read methods of the UDPSocket class, you should never call them. Doing so will cause a RuntimeException to be raised (with an appropriate message set). This is so the internal protocol is enforced.
If you are subclassing a EasyUDPSocket, you must call the Super class’s constructor in your own subclass’s constructor. The subclass will not work or exhibit “strange” behavior unless this is done. Use the Super keyword for this.
The DataAvailable event of the UDPSocket class is not available.
The EasyUDPSocket class provides a simple “wrapper” around the UDPSocket class that makes easier for beginners to get started with UDP networking. With the EasyUDPSocket class, you can send messages either to an individual or to an entire group. One main benefit to the EasyUDPSocket class is the way it handles multicasting. It’s a nuisance to look up which IP addresses can be used with multicasting.
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 data is actually a memory block containing a 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.
To send a message to a group, you pass the group name that you have previously assigned to the group using the Register method. This means that you can pass "MyLocalGroup" as the parameter to the Register method and use that string for calls to SendMessageToGroup. To send a message to an individual, you need the IP address of the user&‘s computer in the SendMessageToIndividual method.
You can still pass a valid Class D IP address and it will be used. One other helper function is the Bind function. This sets up the socket for you properly (so you don’t have to set RouterHops or SendToSelf up yourself) and does the bind on the port specified.
One thing to keep in mind is that EasyUDPSocket defaults to having SendToSelf on. You are welcome to override this default yourself by setting SendToSelf to False after the making the Bind call. While you can still call [Join/Leave]MulticastGroup, we suggest that you only use Register and Unregister for your EasyUDPSocket application.