아우 ㅠㅠ Socket Connect 만 가지고 벌써 3주째 시름 한 결과...

보안 정책 문제로 Cross_Domain 사용시엔 접근 제한이 걸린다.

그래서 보안정책 문서를 CIient로 보내줘야 한다...

그래서 필요 한것이...

PolicyServer... 결국엔 서버쪽에 흡수 되어야 하지만...

지금은 두개 띄어 놓고 사용한다...

3주간의 묶인 스트레스가 한방에 날라간다...

더 좀 짜증스러운건 이글을 2주전에 보긴 봤다는건데...

그냥 대충 읽고 넘어갔다는것이다... 아놔 답답한 색히 ㅡㅡ

MS SilverLight 페이지 예제에도 이런건 없었으니... 그래서 괜찮겠지하고 넘어갔는데...

이번 Bata2 부터 적용 된거란다... 그럼 그따위 동영상 지워버리던가~!!!!!!!!!!!!!!!!!!

어쩄든 해결해서 너무 너무 다행이다...

이제 어서 어서 채팅 프로그램을 만들어야지...

--  ClientAcceesspolicy.xml  --

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from>
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <socket-resource port="4502-4534" protocol="tcp"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

--  PolicyConnection.cs  --

class PolicyConnection
    {
        private Socket _connection;
        private byte[] _buffer;
        private int _received;
        private byte[] _policy;

        private static string _policyRequestString = "<policy-file-request/>";
        public PolicyConnection(Socket client, byte[] policy)
        {
            _connection = client;
            _policy = policy;

            _buffer = new byte[_policyRequestString.Length];
            _received = 0;

            try
            {
                _connection.BeginReceive(_buffer, 0, _policyRequestString.Length,
                                              SocketFlags.None, new AsyncCallback(OnReceive),
                                              client.RemoteEndPoint.ToString());
            }
            catch (SocketException)
            {
                _connection.Close();
            }
        }

        private void OnReceive(IAsyncResult res)
        {
            try
            {
                _received += _connection.EndReceive(res);

                if (_received < _policyRequestString.Length)
                {
                    _connection.BeginReceive(_buffer, _received,
                                         _policyRequestString.Length - _received,
                                         SocketFlags.None, new AsyncCallback(OnReceive), null);
                    return;
                }

                string request =
                              System.Text.Encoding.UTF8.GetString(_buffer, 0, _received);
                if (StringComparer.InvariantCultureIgnoreCase.Compare
                                                                       (request, _policyRequestString) != 0)
                {
                    _connection.Close();
                    return;
                }

                Console.Write("Sending Policy...\n");
                Console.Write(string.Format("Sending policy to {0}\n",res.AsyncState));
                _connection.BeginSend(_policy, 0,  _policy.Length, SocketFlags.None,
                                                                     new AsyncCallback(OnSend), null);
            }
            catch (SocketException)
            {
                _connection.Close();
            }
        }

        public void OnSend(IAsyncResult res)
        {
            try
            {
                _connection.EndSend(res);
            }
            finally
            {
                _connection.Close();
            }
        }
}

--  PolicyServer.cs  --

class PolicyServer
    {
        private Socket _listener;
        private byte[] _policy;

        public PolicyServer(string policyFile)
        {
            FileStream policyStream = new FileStream(policyFile, FileMode.Open);

            _policy = new byte[policyStream.Length];
            policyStream.Read(_policy, 0, _policy.Length);
            policyStream.Close();

            _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
                                                                                             ProtocolType.Tcp);
            _listener.SetSocketOption(SocketOptionLevel.Tcp,
                                              (SocketOptionName) SocketOptionName.NoDelay, 0);
            _listener.Bind(new IPEndPoint(IPAddress.Any, 943));
            _listener.Listen(10);
            _listener.BeginAccept(new AsyncCallback(OnConnection), null);
        }

        public void OnConnection(IAsyncResult res)
        {
            Socket client = null;

            try
            {
                client = _listener.EndAccept(res);
            }
            catch (SocketException)
            {
                return;
            }

            PolicyConnection pc = new PolicyConnection(client, _policy);

            _listener.BeginAccept(new AsyncCallback(OnConnection), null);
        }

        public void Close()
        {
            _listener.Close();
        }
    }


--  Program.cs  --

class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Starting...\n");
            PolicyServer ps = new PolicyServer(@"파일경로\clientaccesspolicy.xml");
            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
        }
    }


- 이 글은 길버라이트님의 http://gilverlight.net/2897 에서 가져왔습니다.

Dev Tistory.../SilverLight Tistory l 2008/09/01 14:42
1  ... 17 18 19 20 21 22 23 24 25  ... 44 

카테고리

분류 전체보기 (44)
His-story... (5)
My Tistory... (10)
Waiting...... (0)
My Friend Tistory... (3)
My Faith Tistory (0)
Ubuntu Tistory... (3)
Dev Tistory... (6)
WoW Tistory... (4)
College Tistory (3)
Working Tistory (3)
ETC... (7)

달력

«   2009/07   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

최근에 받은 트랙백

get rsstistory! Tistory Tistory 가입하기!