1.0.1 • Published 6 months ago

csharpudpdiscovery v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

UDP Network Discovery for C

Overview

This NPM package provides a simple and lightweight solution for UDP network discovery in C# applications. It allows you to easily discover and communicate with devices or services on your local network using the User Datagram Protocol (UDP).

Installation

You can install this package using NPM:

npm install udp-network-discovery-csharp

Alternatively, you can add it to Unity with a scoped registry

registry.npmjs.com

Usage

  1. Create a DiscoveryService instance:
DiscoveryService discovery = new DiscoveryService("MyServer", 1000, 25565);

Use parameters to configure polling intervals and UDP port to use.

  1. Start the discovery advertisement:
discovery.StartAdvertising();
  1. Listen for incoming discovery messages:
discovery.onHostIp += () =>
{
    string message = args.Message; // The received message.    
    // Handle the received message.
};
discovery.StartListening();
  1. Set discovery messages to the network during advertisement:
discovery.SetAdvertisement("Hello, network!");
  1. Stop the discovery service when you're done:
discovery.StopAsyncTasks();

Note that it stops both listeners and advertisers

Example

Here's a simple example of how to use this package to discover devices or services on your local network in Unity context:

public class ExampleUDP : MonoBehaviour
{
    //This example can be run on the same machine. Editor will be the host, and Standalone build will be the client. Just run the client after the host, and check the console for the Host ip address.
    void Start()
    {
        DiscoveryService discoveryService = new DiscoveryService();
        #if !UNITY_EDITOR
        discoveryService.SetAdvertisement(SystemInfo.deviceName);
        discoveryService.StartAdvertising();
        #else
        discoveryService.StartListening();
        #endif
    }    
}

License

This package is provided under the MIT License.

Author

This package is maintained by Mykhailo "Hyst3r1a" Gorshenin. You can contact me at miklehigaran@gmail.com.

Happy network discovery with C#! 🚀

1.0.1

6 months ago

1.0.0

6 months ago