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");
RT @as3gamegears: New: p2plocal (lib for local P2P connections, serverless RTMFP) http://t.co/IGl9kpOUtD #as3 #flash #gamedev
@as3gamegears This looks so simple to use, question is can it handle more than 2 devices at once? If one device sends a msg do all receive?
Andrey Kyznetsov liked this on Facebook.
Great concept! Is this a more streamlined version of AS3MUL?
Yeah, I would say that, Bill. Both have pros and cons and p2plocal seems to be dead simple to setup and use. Regarding AS3MUL,I’ve used it and it’s also an easy to use lib, but the API is far more powerful IMO.
hello,
When compiling it’s asking for definition of teachbase.ru (import ru.teachbase.utils.Strings; in P2Pconfig).
Is there any way to work without?
best,
q
Hello! I haven’t used the lib, so I never faced that error. Probably that missing
Strings
class is aString
class on steroids.I think you could try to replace
Strings
withString
.