2012-02-20 2 views
0

특정 포트에 연결되면 xampp/wamp 기반 Apache 서버에서 사용자 정의 요청시 사용자 정의 응답을 보낼 수 있습니까?xampp/wamp 기반 Apache 서버 사용자 정의 응답

플래시 앱이 crossdomain http GET 요청을 허용하도록 요청하는 \ 0에 답장을 보내려고합니다.

플래시 정책 요청은 기본적으로 포트 843으로 만들어 지므로이를 그대로 유지하고 싶습니다. 내가 아는 한

<?xml version="1.0"?> 
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd"> 
    <cross-domain-policy> 
     <site-control permitted-cross-domain-policies="master-only"/> 
     <allow-http-request-headers-from domain="*" headers="*" secure="true" /> 
     <allow-access-from domain="*" to-ports="*" /> 
    </cross-domain-policy> 

, 요청이 있어야한다 반환 :

포트는 \ (널 문자로 끝나는, \ 0은 단지 참고 용이며) 0과 같은 뭔가 회신을 받아야합니다 Content-type이 필요하지만 일반 텍스트로도 사용할 수 있습니다.

다음을 사용해 보았습니다. http://socketpolicyserver.com/ 포트를 수신하고 연결을 허용하지만 요청시 지정된 xml로 응답하지 않습니다. 어떤 방법/적절한 응답을 달성하는 방법을 이해할 수있을 것이다

, 관련하여

,

마이크.

--- UPDATE --->

I 포트 843을 청취하고, 상기 정책을 제공하는 간단한 C# 웹 서버 쓴

! - SecureSocket의 연결을 사용하는 경우, 그러나, 그것은 잘 밖으로 일을 보안 연결 (즉, 소켓을 HTTPS/SSL 프로토콜로 여는 것) - 전송 된 요청은 호스트 인증서를 사용하여 암호화됩니다. 내가 아는 한, 서버 인증서를 청취하거나 획득하고 외부 앱을 통해 데이터를 암호 해독 할 수있는 방법이 없기 때문에, 유일한 방법은 Apache가 올바른 요청을받은 후 Apache가 crossdomain 정책에 응답하도록 '가르치는 것'입니다. 적절한 포트.

내가 가진 또 다른 아이디어는 서버 자체에서 일어나는 일과 상관없이 Apache 디렉토리에 저장된 서버의 인증서 파일을 읽는 것입니다.하지만 과장은 아닙니다.

귀하의 의견을 듣고 싶어요,

마이크. 나는 일부 수정이 녀석 코드를 사용했습니다

: http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server

및 포트 843을 청취 간단한 멀티 쓰레드 웹 서버를 생성하고, 다소 일반을 제공 그래서 여기

답변

0

내가 결국 그것을 해결 방법 적절한 플래시 요청시 정책.

Adobe에서 제공 한 몇 가지 예가 있지만 어떤 이유로 인해 창문이 좋지 않습니다.

플래시의 SecureSocket 개체를 사용하는 경우 대상 서버 (IIS '/ Apaches'/ Tomcats '등 ..)의 SSL 자격 증명을 사용해야하며 다음과 같은 공개 키를 사용하여 클라이언트 인증을 시작합니다. 대상 서버 인증서, 다시 말하지만이 코드는 SSL 지원을 지원하지 않기 때문에 C#의 SSL 스트림을 사용하여 구현하기 시작했습니다. SSL을 통해 작동하도록 할 수 있다면 알려주십시오.

이 코드가 도움이 될 것이라고 희망한다면,

마이크.

using System; 
using System.Text; 
using System.Net.Sockets; 
using System.Threading; 
using System.Net; 
using System.IO; 

namespace TCPSexyServer 
{ 
    class Server 
{ 
    private TcpListener tcpListener; 
    private Thread listenThread; 

    private void ListenForClients(int p) 
    { 
     throw new NotImplementedException(); 
    } 

    public Server() 
    { 
     this.tcpListener = new TcpListener(IPAddress.Any, 843); 
     this.listenThread = new Thread(new ThreadStart(ListenForClients)); 
     this.listenThread.Start(); 
    } 

    private void ListenForClients() 
    { 
     this.tcpListener.Start(); 

     while (true) 
     { 
      //blocks until a client has connected to the server 
      TcpClient client = this.tcpListener.AcceptTcpClient(); 

      //create a thread to handle communication 
      //with connected client 
      Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm)); 
      clientThread.Start(client); 
     } 
    } 

    private void HandleClientComm(object client) 
    { 
     TcpClient tcpClient = (TcpClient)client; 
     NetworkStream clientStream = tcpClient.GetStream(); 
     byte[] message = new byte[4096]; 
     int bytesRead; 

     while (true) 
     { 
      bytesRead = 0; 

      try 
      { 
       //blocks until a client sends a message 
       bytesRead = clientStream.Read(message, 0, 4096); 
      } 
      catch 
      { 
       //a socket error has occured 
       break; 
      } 

      if (bytesRead == 0) 
      { 
       //the client has disconnected from the server 
       break; 
      } 

      //message has successfully been received 

      UTF8Encoding encoder = new UTF8Encoding(); 

      string sentData = encoder.GetString(message, 0, bytesRead); 
      Console.WriteLine(sentData); 
      if (sentData == "<policy-file-request/>\0") 
      { 
       String policy = "<?xml version=\"1.0\"?>\n" + 
           "<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\n" + 
           "<cross-domain-policy>\n" + 
           "<site-control permitted-cross-domain-policies=\"master-only\"/>\n" + 
           "<allow-http-request-headers-from domain=\"*\" headers=\"*\" secure=\"true\" />\n" + 
           "<allow-access-from domain=\"*\" to-ports=\"*\" />\n" + 
           "</cross-domain-policy>\0"; 
       byte[] buffer = encoder.GetBytes(policy); 
       clientStream.Write(buffer, 0, buffer.Length); 
       clientStream.Flush(); 
       Console.WriteLine(policy); 
      } 
      else 
      { 
       tcpClient.Close(); 
      } 
      System.Diagnostics.Debug.WriteLine(encoder.GetString(message, 0, bytesRead)); 
     } 

     tcpClient.Close(); 
    } 

     public static void Main(string[] args) 
     { 
      Server blah = new Server(); 
     } 

    } 
}