Code Monkey home page Code Monkey logo

beacon's Introduction

Beacon: automatic network discovery

Beacon is a small C# library that helps remove some of the user annoyances involved in writing client-server applications: finding the address of the server to connect to (because messing around putting in IP addresses is so much fun, eh?)

In that sense, it fills the same niche as other tools like Apple's Bonjour, but with minimal dependencies.

How it works

UDP broadcasts, what else did you expect? :) It doesn't work outside your own network range without an external server (support for something like this could be added...!) but inside one network it works quite well.

The current Beacon implementation has support for local advertising based on application type (so different programs both using Beacon don't interfere with each other), and advertising server-specific data, which can be used to distinguish different servers from each other (for example, by presenting a display name to the user).

Starting a Beacon server

Starting a beacon (to make a server discoverable) is simple:

var beacon = new Beacon("myApp", 1234);
beacon.BeaconData = "My Application Server on " + Dns.GetHostName();
beacon.Start();

// ...

beacon.Stop();

1234 is the port number that you want to advertise to clients. Typically, this is the port clients should connect to for your actual network service. You can fill in a bogus value if you don't need it.

Scanning for servers using a Probe

Clients can find beacons using a Probe:

var probe = new Probe("myApp");
// Event is raised on separate thread so need synchronization
probe.BeaconsUpdated += beacons => Dispatcher.BeginInvoke((Action)(() => {
    for (var beacon in beacons)
    {
        Console.WriteLine(beacon.Address + ": " + beacon.Data);
    }        
}));

probe.Start();

// ...

probe.Stop();

A WPF dialog is included that you can present to users to let them pick a server.

Help wanted

This repository currently contains a simple C# implementation of the Beacon protocol. Implementations in other languages and for other platforms (Android, iOS, C++) are very welcome, as well as improvements to the protocol.

beacon's People

Contributors

rix0rrr avatar rob-v avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.