Skip to main content
May 27, 2011
Question

NetConnection.Connect.Failed

  • May 27, 2011
  • 1 reply
  • 1713 views

why can't i connect?

my code:

package
{
  import flash.display.Sprite;
  import flash.media.Camera;
  import flash.media.Microphone;
  import flash.media.Video;
  import flash.net.NetConnection;
  import flash.net.NetStream;
  import flash.net.ObjectEncoding;
  import flash.events.NetStatusEvent;

  public class MinCam extends Sprite
  {
        private var cam:Camera;
        private var mic:Microphone;
        private var vid1:Video;
        private var vid2:Video;
        private var nc:NetConnection;
        private var nsOut:NetStream;
        private var nsIn:NetStream;
        private var rtmpNow:String;
        private var msg:Boolean;

        public function MinCam ()
        {
             cam = Camera.getCamera();
             mic = Microphone.getMicrophone();
             rtmpNow = "rtmp://localhost/live";
            nc = new NetConnection;
            nc.addEventListener(NetStatusEvent.NET_STATUS, connected)

             //Camera Settings
             cam.setKeyFrameInterval (15);
             cam.setMode (240,180,15,false);
             cam.setMotionLevel (35,3000);
             cam.setQuality (40000 / 8,0);

             //Microphone Settings
             mic.gain = 85;
             mic.rate= 11;
             mic.setSilenceLevel (25,1000);
             mic.setUseEchoSuppression (true);

             //Connect
             nc.connect (rtmpNow);

             //Video Setup
             vid1=new Video(cam.width,cam.height);
             vid2=new Video(cam.width,cam.height);
             addChild (vid1);
             vid1.x=10,vid1.y=20;
             addChild (vid2);
             vid2.x=vid1.width+15,vid2.y=20;

             //Attach local video and camera
             vid1.attachCamera (cam);

            
        }
       
          public function connected(Event:NetStatusEvent):void
        {
              trace(Event.info.code)
            switch (Event.info.code)
            {
                case "NetConnection.Connect.Success":
                nsOut = new NetStream(nc);
                 nsIn = new NetStream(nc);
                 //NetStream
                 nsOut.attachAudio (mic);
                 nsOut.attachCamera (cam);
                 nsOut.publish ("camstream");
                 vid2.attachNetStream (nsIn);
                 nsIn.play ("camstream");
                trace('connected')
                break;
            }
        }
       
  }
}

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    May 27, 2011

    Are you sure your FMS is up - NetConnection.Connect.Failed comes when client was not able to reach server kind - which would happen when FMS is down or your FMS is running on some other machine and your client is on some other machine as i see you are using localhost. If your FMS is one "A" machine and your client in on "B" machine please put "ip address" or "domain name" of "A" machine where FMS is in Netconnection URI i.e. "rtmp://ipaddressofA/live"

    May 27, 2011
    Are you sure your FMS is up - NetConnection.Connect.Failed comes when  client was not able to reach server kind - which would happen when FMS  is down or your FMS is running on some other machine and your client is  on some other machine as i see you are using localhost. If your FMS is  one "A" machine and your client in on "B" machine please put "ip  address" or "domain name" of "A" machine where FMS is in Netconnection  URI i.e. "rtmp://ipaddressofA/live"

    my fms is on and it is on the same computer as my flash document

    June 8, 2011

    I Just tried it again and it worked