Skip navigation
Gabi_HUN
Currently Being Moderated

Why is rtmfp not working with these parameters and functions?

Feb 2, 2013 3:46 PM

Tags: #rtmfp #netstream #netconnection

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://p2p.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;
}

Notes:

  • initConnection initializes the NC, sendInit initializes the send stream
  • receiveInit initializes the incoming stream based on the far peer id which I copy paste intoincomingID.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 initialize the sending stream (sendInit) on application 1.
  • I copy the far peer id to application 2. and run receveInit.

 

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.

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points