2013-03-15 6 views
1

왜 연결할 수 없습니까? 응용 프로그램을 실행할 때 출력에서 ​​NetConnection.failed가 수신됩니다. 제 코드를주의 깊게 살펴 주시겠습니까? 내 문자열 URL이 정확하다고 생각합니다. 내 FMS가 다운되었거나 코드 오류가 있는지 확실하지 않습니다.FMS에 연결할 수 없습니다.

는 서버가 다른 시스템에있는 경우 rtmfp://localhost/streamExample 와 서버의 URL을 변경해야합니다

import flash.net.NetConnection; 
import flash.events.NetStatusEvent; 
import flash.net.NetStream; 
import flash.media.Camera; 
import flash.media.Video; 
import flash.media.Microphone; 
import fl.controls.Button; 

var nc:NetConnection; 
var ns:NetStream; 
var cam:Camera; 
var microphone:Microphone; 
var vid:Video; 
var connectButton:Button; 

//Connecting to Flash Media Server 
nc = new NetConnection(); 

nc.connect("rtmfp:/fms/streamExample"); 

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler); 

function netHandler(event:NetStatusEvent):void 
{ 
    switch (event.info.code) 
    { 
     case "NetConnection.Connect.Success": 
     { 
      connectButton.label = "Disconnect"; 
      connectButton.enabled = true; 
      sendButton.enabled = true; 
      onConnect(); 
      break; 
     } 

     case "NetConnection.Connect.Closed": 
     { 
      connectButton.label = "Connect"; 
      connectButton.enabled = true; 
      sendButton.enabled = false; 
      nc.close(); 
      break; 
     } 

     case "NetConnection.Connect.Failed": 
     { 
      trace("Sorry your connection failed"); 
      break; 
     } 

     case "NetConnection.Connect.Rejected": 
     { 
      trace("Oops the connection has been rejected"); 
      break; 
     } 
    } 
} 
ns = new NetStream(nc); 

ns.publish("live", "viewing"); 

ns.attachCamera(); 


//Setting the video 
var vid:Video = new Video(); 
vid.height = cam.height; 
vid.width = cam.width; 
vid.x = 10; 
vid.y = 10; 
addChild(vid); 

cam = Camera.getCamera(); 
cam.setMode(400, 300, 20); 
cam.setQuality(0, 85); 
cam.setKeyFrameInterval(18); 
vid.attachCamera(); 
addChild(cam); 

//Setting the audio 
microphone = Microphone.getMicrophone(); 
microphone.codec = SoundCodec.SPEEX; 
microphone.framesPerPacket = 1; 
microphone.setSilenceLevel(0, 200); 
microphone.gain = 50; 
NetStream.attachAudio(microphone); 
+0

' "RTMFP :/FMS/streamExample"'유효한 연결 문자열이 아닌 여기에

이 모든 표시가있는 샘플입니다. ''rtmfp : //server.com/applicationName ''rtmfp에는 많은 뉘앙스가 있습니다. rtmp로 응용 프로그램을 작동 시키십시오 (누락 된'f '참고). – BadFeelingAboutThis

+0

또한, '연결'을 모범 사례로 호출하기 전에 인터넷 연결 리스너를 추가해야 할 것입니다. – BadFeelingAboutThis

답변

1

플래시 미디어 서버가 귀하의에서 응용 프로그램을 테스트하는 것보다 동일한 시스템에있는 경우 , 감사합니다 localhost을 서버를 실행하는 시스템의 IP 주소로 바꾸면됩니다.

connect() 호출을 수행하기 전에 NetConnection에도 이벤트 수신기를 추가해야합니다.

오류의 원인을 알 수 있도록 이벤트 설명을 추적 할 수 있습니다.

nc = new NetConnection(); 
nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler); 
nc.connect("rtmfp:/localhost/streamExample"); 

function netHandler(event:NetStatusEvent):void 
{ 
    switch (event.info.code) 
    { 
     case "NetConnection.Connect.Success": 
     { 
      connectButton.label = "Disconnect"; 
      connectButton.enabled = true; 
      sendButton.enabled = true; 
      onConnect(); 
      break; 
     } 
     case "NetConnection.Connect.Closed": 
     { 
      connectButton.label = "Connect"; 
      connectButton.enabled = true; 
      sendButton.enabled = false; 
      nc.close(); 
      break; 
     } 
     case "NetConnection.Connect.Failed": 
     { 
      trace("Sorry your connection failed"); 
      trace("Reason is: " + event.info.description); 
      break; 
     } 
     case "NetConnection.Connect.Rejected": 
     { 
      trace("Oops the connection has been rejected"); 
      break; 
     } 
    } 
} 
+0

감사합니다! 그리고 늦은 뒤늦은 회신에 정말 유감입니다. 문제는 문자열 주소가 잘못되었습니다. 어떤 이유로 나는 이벤트 리스너를 nc.connect 후에 넣었을 것이라고 생각했지만 팁을 주셔서 감사합니다. – user2160610

+0

@ user2160610 도움이 다른 사람을 도울 수있는 답변을 수락하는 것을 잊지 마십시오. – duTr