Skip to content
This repository has been archived by the owner. It is now read-only.
Providing a simple interface to broadcast messages within the local network over UDP.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Icons
UDPBroadcast.Example
UDPBroadcast.Net40
UDPBroadcast.Net45
UDPBroadcast.Net46
UDPBroadcast.nupkg
.gitattributes
.gitignore
LICENSE
README.md
UDPBroadcast.sln

README.md

Icon csharp-UDPBroadcast

This project's aim is to provide a simple interface to broadcast messages within the local network by using UDP. Just in case you can't do any Zeroconf, UPnP, PGM, or message queuing with publish semantics to register and publish services with zero to none configuration effort.

Installing NuGet Status

https://www.nuget.org/packages/UDPBroadcast/

PM> Install-Package UDPBroadcast

Usage

using System;
using UDPBroadcast;

[Serializable] // is needed as we are using BinaryFormatter internally by default
public sealed class Foo
{
  public string Bar { get; set; }
}

var messageSerializer = new MessageSerializer();
var messageBodySerializer = new MessageBodySerializer();
var messageFactory = new MessageFactory();
var pathFactory = new PathFactory();
using (var broker = new Broker(1337,
                               messageSerializer,
                               messageBodySerializer,
                               messageFactory,
                               pathFactory))
{
  var messageObserver = new MessageObserver<Foo>(broker.ID)
  {
    InterceptRemoteMessagesOnly = false,
    InterceptOnNext = foo =>
    {
      // yolo
    }
  };
  broker.Subscribe(messageObserver);
  broker.Start();

  broker.Publish(new Foo
  {
    Bar = "hello"
  });

  Console.ReadLine(); // or whatever mechanism you want to use to block in this example
}

Adapting serialization/creation ...

IMessageFactory You can inject your own IMessageFactory implementation, to send eg CustomMessage instances instead to default Message.

IMessageSerializer Instead of using the default BinaryFormatter as the serializer of IMessage instances, you can provide your own serialization mechanism.

IMessageBodySerializer Instead of using the default BinaryFormatter as the serializer of IMessage.Body, you can provide your own serialization mechanism.

IPathFactory If you ever come across the need to adapt routing from the default Type.FullName of the encapsulated instance, you can provider your own implementation.

License

csharp-UDPBroadcast is published under WTFNMFPLv3.

Spotify Playlist

While implementing this project, I listened to this playlist. If you want to make adaptions to the project, I strongly recommend listening to this playlist, as it gets you in the right mood.

Icon

paper plane by Jems Mayor from the Noun Project.

You can’t perform that action at this time.