Skip to main content
May 27, 2011 2:45 PM UTC
Question

NetConnection.Connect.Failed

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 is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    Participating Frequently
    May 27, 2011 3:13 PM UTC

    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"

    Translate
    May 27, 2011 10:29 PM UTC
    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

    Translate
    Jun 8, 2011 12:41 AM UTC

    I Just tried it again and it worked

    Translate