p2plocal is a library for local P2P connections (serverless RTMFP). The library allows developers to create new local net group with just one call using a configuration Object, exchange typed messages, use direct routing (peer-to-peer send message) and automatically restore a session state (if there is at least one peer in the group).

The library is useful to create local multiplayer games, where a connection to the outside network (e.g. Internet) is not required. The communication is handled using events and the typed messages allow the developer to listen to specific message types.

Sample

//create new instance
p2p_client = new P2PClient();

// add listener for 'connect' event: it means connection established
// and you are connected to NetGroup; if you don't need to restore
// a state - that's enough
p2p_client.addEventListener(P2PEvent.CONNECTED, onConnect);
// add listener for 'state_restored' event: it means all previously
// dispatched messages within the group has been received and
// ready to be parsed;
p2p_client.addEventListener(P2PEvent.STATE_RESTORED, onStateRestored);

// add listener for messages of a type "message"
p2p_client.listen(messageReceived, "message");

p2p_client.connect(new P2PConfig({
    groupName: "example",      // NetGroup name
    saveState: "true"          // restore state from previous messages
}));

// state restored
function onStateRestored(e:P2PEvent):void {
    // e.info.state contains an Array of messages
}

// receive messages
function messageReceived(p:P2PPacket):void{
  // handle message; p.data contains data was sent
}

// send messages: p2p_client.send(data, type, system, recipient);
p2p_client.send(data, "message");
Multiplayer . URL.