RTMFP, where did all my neighbors go?

Posted by on May 14, 2011

So while RTMFP is great for peer to peer connections, it does have some considerations that you need to take into account when using it. The biggest, knowing when peers connect and disconnect to the app.

When a peer connects, the app will receive a NetStatusEvent. The event’s info.code will be a “NetGroup.Neighbor.Connect”. You can use the info.neighbor as a unique identifier for the connected peer.

The nice thing, is if a peer comes in late to the p2p party, as soon as a peer sends a message that is received by yours, then the connect event will be fired. So you’ll always have a list of peers that have connected to your client.

When a peer needs to disconnect, it should call the NetGroup’s close() method. This will send out a packet letting all other peers know that it has disconnected.

The interesting thing is, this is RTMFP, so not all packets will get to all peers. So what happens if your client doesn’t receive the disconnect packet? How do you know that your list of connected peers isn’t stale? Good question. One I don’t yet have an answer to. So if any of you do, please let me know.