opensourceautomation / Open-Source-Automation

Open Source Automation is a home and commercial automation engine
www.opensourceautomation.com
GNU Lesser General Public License v3.0
97 stars 62 forks source link

Service - Add generic UDP method. #312

Closed VaughnRupp closed 8 years ago

VaughnRupp commented 8 years ago

New non-plugin clients and non-standard servers need access to a scriptable method to send UDP broadcasts.

VaughnRupp commented 8 years ago

I have added a Broadcast method to the Service object type now. I left it hardcoded at 10051 for an IP, but Param 1 = Group which you can pick a unique group name to keep other listeners from hearing the message.

I have not tested it, but the code it pretty simple, so I hope it works.

Here is the code to send the message. Put whatever you want in param2 and parse it if you need multiple fields. Other code is currently splitting on |

case "BROADCAST": Log.Info("-> UDP: " + method.Parameter1 + ", " + method.Parameter2); UDPConnection.SendObject(method.Parameter1, method.Parameter2, new IPEndPoint(IPAddress.Broadcast, 10051)); break;