multicast

Haxe UDP multicast library for hxcpp.
http://github.com/jcward/hx-multicast

To install, run:

haxelib install multicast 0.0.2 

See using Haxelib in Haxelib documentation for more information.

README.md

hx-multicast

Haxe UDP multicast library for hxcpp

Build Status

About

A simple UDP multicast library for Haxe / HXCPP, in simple .hx source, no extra ndlls or build steps.

Works with hxcpp 3.4.49 up to the current release 4.0.4.

UDP multicast allows message passing between many clients (devices or processes) on the same local area network (LAN), transmitting messages between them without any IP or host information. Messages sent from any client are delivered to all other clients.

Note that some routers, networks, or devices may not support UDP multicast. Also, with UDP, packets are not guaranteed to arrive, and are not guaranteed to arrive in the order they were sent. You should assume any packet could be lost.

Typical use cases are low-latency, low-bandwidth message passing. All message serializations must fit in the pre-allocated buffer size.

Example Usage

Install with haxelib install multicast, and add -lib multicast to your hxml. For OpenFL, add <haxelib name="multicast" /> to your project.xml file.

Example Test.hx:

class Test
{
  public static function main()
  {
    var mc = new multicast.Client();
    trace('I am: ${ mc.uid }');

    // My uid: mc.uid
    var peers = [ mc.uid ];

    // In a typical game setting, instead of a Timer, you might
    // send+check messages from your event loop.
    var t = new haxe.Timer(2000);
    t.run = function() {
      mc.emit({ type:"ping" });
      while (mc.has_next()) {
        var payload = mc.read();
        if (payload!=null && peers.indexOf(payload.from_uid)<0) {
          trace('Hello, ${ payload.from_uid } !');
          peers.push(payload.from_uid);
        }
      }
    }

  }
}

// ... some time later, cleanup
// t.stop();
// mc.close();

Running this test from two different terminals:

image

Contributors
jeff.ward
Version
0.0.2
Published
8 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂