Code Monkey home page Code Monkey logo

hx-multicast's Introduction

hx-multicast

Haxe UDP multicast library for hxcpp. Alpha / proof of concept -- feedback appreciated!

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

hx-multicast's People

Contributors

jcward 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.