0

I wrote some basic functions in ActionScript in order to use RTMFP:

import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.ui.Keyboard;

private var serverAddress:String = "rtmfp://cc.rtmfp.net/";
private var serverKey:String = "xxxxx";
private var netConnection:NetConnection;
private var outgoingStream:NetStream;
private var incomingStream:NetStream;

private function initConnection():void {
    netConnection = new NetConnection();
    netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
    netConnection.connect(serverAddress + serverKey);
}

private function netConnectionHandler(event:NetStatusEvent):void {
    receivedMessages.text += "NC Status: " + event.info.code + "\n";

    //Some status handling will be here, for now, just print the result out.
    switch (event.info.code) {
        case 'NetConnection.Connect.Success':
            receivedMessages.text += "My ID: " + netConnection.nearID + "\n";
            break;
    }
}

private function sendInit():void {
    outgoingStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
    outgoingStream.addEventListener(NetStatusEvent.NET_STATUS, outgoingStreamHandler);
    outgoingStream.publish("media");

    var sendStreamObject:Object = new Object();
    sendStreamObject.onPeerConnect = function(sendStr:NetStream):Boolean {
        receivedMessages.text += "Peer Connected ID: " + sendStr.farID + "\n";
        return true;
    }

    outgoingStream.client = sendStreamObject;
}

private function receiveInit():void {
    receivedMessages.text += "Initializing Receiving Stream: " + incomingID.text + "\n";

    incomingStream = new NetStream(netConnection, incomingID.text);
    incomingStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
    incomingStream.play("media");
    incomingStream.client = this;
}

public function receiveMessage(message:String):void {
    receivedMessages.text += "Received Message: " + message + "\n";
}

private function outgoingStreamHandler(event:NetStatusEvent):void {
    receivedMessages.text += "Outgoing Stream: " + event.info.code + "\n";
}

private function incomingStreamHandler(event:NetStatusEvent):void {
    receivedMessages.text += "Incoming Stream: " + event.info.code + "\n";
}

private function sendMessage():void {   
    outgoingStream.send("receiveMessage", toSendText.text);
}

private function disconnectNetConnection():void {
    netConnection.close();
    netConnection.removeEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
    netConnection = null;
}

private function disconnectOutgoing():void {
    outgoingStream.close();
    outgoingStream.removeEventListener(NetStatusEvent.NET_STATUS, outgoingStreamHandler);
    outgoingStream = null;
}

private function disconnectIncoming():void {
    incomingStream.close();
    incomingStream.removeEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
    incomingStream = null;
}
  • initConnection initializes the NC, sendInit initializes the send stream, receiveInit initializes the incoming stream based on the far peer id which I copy paste into incomingID.text
  • I print every results into receivedMessages.text
  • I do not have firewall, nor NAT.
  • The Adobe sample application (http://labs.adobe.com/technologies/cirrus/samples/) works perfectly.

The procedure I follow:

  • Initialize NC on application 1. (sender)
  • Initialize NC on application 2. (receiver)
  • I copy the far peer id to application 2. and run receveInit.
  • I initialize the sending stream (sendInit) on application 1.

Note: I tried to reverse the last 2 procedure, doesent work either way.

After this, I execute sendMessage() which reads the message from toSendText.text.

Does not working. Why? What is wrong with my codes?

Thank you for every helpful answer in advance.

Gábor DANI
  • 2,063
  • 2
  • 22
  • 40
  • Maybe because your timing is off? These connections are event based. You need to listen for NetStream.Play.Start to know that the other user has successfully connected to your published stream before you can send anything on that stream with sendMessage(). There are many many other state events that fire for connections and streams that you should look into [NetStatusEvent codes](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/NetStatusEvent.html) – Jason Reeves Feb 02 '13 at 18:42
  • Thank you. The incomingStreamHandler would print out evert event that is triggered on incomingStream. It does not print out anyting on connect, if there is any connection at all, I dont know why. – Gábor DANI Feb 05 '13 at 16:43

3 Answers3

1

because cc.rtmfp.net is the connectivity checker, not the P2P introduction service (p2p.rtmfp.net). cc performs some quick tests, sends the results, and disconnects. it performs no other functions nor provides any other services.

0

I found out.

For developing and testing, I use Mac and I tested the application there. Did not work. Still doesen't work. On Windows, it works perfectly.

Strange.

Gábor DANI
  • 2,063
  • 2
  • 22
  • 40
0

You have to add Handler for receiveMessage(). Otherwise it is just a function that you have to call it.

Moradnejad
  • 3,466
  • 2
  • 30
  • 52