[MFC] HTTP 연결(Connection) 기본 소스

Posted at 2010/04/12 01:07 // in Programming // by 엔신
#include <afxinet.h>

    CInternetSession*    pSession = NULL;
    CHttpConnection*    pHttpConnect = NULL;
    CHttpFile*            pHttpFile = NULL;
    CString                url = _T("tc/index.php");

    try{
        
        // HTTP 메소드별로 사용 가능
        pSession = new CInternetSession;

        pHttpConnect = pSession->GetHttpConnection(_T("www.rain9.com"));

        /* 이런 식으로도 익셉션 처리 가능
        if(pHttpConnect == NULL)
            throw CString(_T("http connection failed!!!"));
        */

        pHttpFile = pHttpConnect->OpenRequest(CHttpConnection::HTTP_VERB_GET, url);

        pHttpFile->AddRequestHeaders(_T("HTTP/1.1\r\nAccept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*\r\nAccept-Language: ko\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.4; CNS_UA; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; CNS_UA)\r\nAccept-Encoding: gzip, deflate\r\nProxy-Connection: Keep-Alive\r\n"));

        pHttpFile->SendRequest();

        // GET 방법으로 간단하게
        /*
        pSession = new CInternetSession;
        pHttpFile = pSession->OpenURL(_T("http://www.rain9.com/tc/index.php"));
        */
        
    }
    catch(CInternetException *m_pEx)
    {
        m_pEx->ReprotError();
        m_pEx->Delete();
    }

    // result값 확인
    DWORD m_dwStatusCode;
    pHttpFile->QueryInfoStatusCode(m_dwStatusCode);

    // 객체 delete 부분
    if(pHttpFile)
    {
        delete pHttpFile;
        pHttpFile = NULL;
    }
    if(pHttpConnect)
    {
        delete pHttpConnect;
        pHttpConnect = NULL;
    }
    if(pSession)
    {
        pSession->Close();
        delete pSession;
        pSession = NULL;
    }

CInternetSession - http://msdn.microsoft.com/en-us/library/be5fa0d9%28v=VS.80%29.aspx
CHttpConnection - http://msdn.microsoft.com/en-us/library/6zsa3dfa%28v=VS.80%29.aspx
CHttpFile - http://msdn.microsoft.com/en-us/library/tzhfwc94%28v=VS.80%29.aspx

이올린에 북마크하기
2010/04/12 01:07 2010/04/12 01:07

VoIP DTMF(Dual Tone Multi-Frequency)

Posted at 2010/04/11 23:56 // in VoIP // by 엔신
VoIP DTMF(Dual Tone Multi-Frequency)

1.전송 방식
    1.1 Out of band
    2.2 In band

1.전송 방식

    1.1 Out of band
    signal message를 통해서 DTMF를 전달하여 전송이 정확한 반면 duration(시간)에 대한 정보가 없어서 길고 짧음을 표현 못한다.
    SIP의 경우 Info 메시지를 통해 전달되며 UDP을 사용한다.
    H.323, MGCP도 Out of band 방식이다.

    --------------------------------------------------------------------
    SIP의 Info 메 시지를 통한 DTMF ‘1’ 전달 예
    1) A사 장비

    INFO sip:0263121725@10.1.1.101:5060 SIP/2.0
    Via: SIP/2.0/UDP 10.1.1.101:5060;branch=z9hG4bK.dlsrks00000.313935
    From: <sip:0263121725@hti.com>;tag=1103321111126510229
    To: <sip:0263121726@hti.com:5060>;tag=18479239141126510229
    Call-ID: 18073a010165400013341@10.1.1.101
    CSeq: 22 INFO
    Max-Forwards: 70
    User-Agent: CallGenerator/1.0.0
    Content-Type: application/vnd.networks.digits
    Content-Length:    35
    p=Digit-Collection
    y=Digits
    d=1


    2) B사 장비
    INFO sip:0263121725@10.1.1.101:5060 SIP/2.0
    Via: SIP/2.0/UDP 10.1.1.101:5060;branch=z9hG4bK.dlsrks00000.46695
    From: <sip:0263121725@hti.com>;tag=1103321111126510229
    To: <sip:0263121726@hti.com:5060>;tag=18479239141126510229
    Call-ID: 18073a010165400013341@10.1.1.101
    CSeq: 23 INFO
    Max-Forwards: 70
    User-Agent: CallGenerator/1.0.0
    Content-Type: audio/telephone-event
    Content-Length:     4
    --------------------------------------------------------------------
   
    같은 INFO 메시지를 이용하더라도 그 전달 형식이 vendor 별로 다르므로 상호 연동을 위해 정규화 과정을 거쳐야겠지만, sniffing 관점에서 보면 헤더나 body 데이터로 쉽게 숫자를 유추 가능할 것으로 보인다.

    2.2 In band
    RTP를 통해 메시지를 전달한다.
   
        2.2.1 Bypass
        bypass 방식은 버튼 소리가 미디어 데이터로 전달이 되어 코덱 압축에 따라 손실이 발생하여 DTMF tone이 오인식될 수 있다.
       
        2.2.2 RFC 2833
        RFC 2833 방식은 RTP 패킷에 DTMF의 번호와 볼륨, daration이 명시 되므로 정확한 편이다. 단, UDP 기반이므로 패킷 손실 우려가 있다.

        bypass : 음성코덱 압축(payload type 0)
        RFC 2833 : rtpevent(payload type 101)


        Bypass 방식은 sdp field에 별도의 형식이 필요없으나 rfc2833은 아래와 같은 sdp 형식을 명시하고 있다.
        ============================================================================
        a=fmtp:<format> <list of values>
        a=fmtp:100 0-15,66,70
        Since all implementations MUST be able to receive events 0 through 15, listing these events in the a=fmtp line is OPTIONAL.
         
        The corresponding MIME parameter is "events", so that the following sample media type definition corresponds to the SDP example above:
        audio/telephone-event;events="0-11,66,67";rate="8000"
         
        아래의 메시지는 C사 장비의 rfc2833 에 사용되는 sdp field를 나타내는 것으로 위의 표준안에 나타난 형식과 차이를 보이고 있다.
         
        1) rfc2833으로 DTMF 전송을 할경우 sdp field (C사 장비)
        v=0
        o=0263121725 1126516338 1126516338 IN IP4 10.1.1.101
        s=-
        c=IN IP4 10.1.1.101
        t=0 0
        m=audio 30004 RTP/AVP 4 101
        a=RTPmap:4 G723/8000
        a=RTPmap:101 telephone-event/8000
         
        위의 메시지는 rfc2833 의 방법에 따라 RTP payload type 101로 DTMF를 전송한다는 것을 나타내고 있다.
         
        2) Bypass 방식으로 DTMF 전송을 할경우 sdp field.
        v=0
        o=0263121725 1126516338 1126516338 IN IP4 10.1.1.101
        s=-
        c=IN IP4 10.1.1.101
        t=0 0
        m=audio 30004 RTP/AVP 4
        a=RTPmap:4 G723/8000
         
        위의 sdp field는 g723 코덱외에 별다른 RTP map에 대한 정보가 없으므로 DTMF tone을 g.723으 로 압축하여 보내는 bypass방식을 지칭한다.   
        ============================================================================

        패킷 헤더 부분 예제)
        a=fmtp:100 0-15,66,70
        해석 : payload type 100, 0~ 15번 event, 66, 70번 이벤트 사용

        audio/telephone-event;events="0-11,66,67";rate="8000"
        해석 : 0~ 11번, 66, 67 event 사용, rate=8000(default임)
       
        payload type 101을 많이 봤는데 101번은 Line lockout tone이라는데 자동 절단 기능의미하는 듯




참고 table

Event  encoding (decimal)
_________________________
0--9                0--9
*                     10
#                     11
A--D              12--15
Flash                 16

Table 1: DTMF named events(버튼 값)


Event                            encoding (decimal)
___________________________________________________
Acceptance tone                                  96
Confirmation tone                                97
Dial tone, recall                                98
End of three party service tone                  99
Facilities tone                                 100
Line lockout tone                               101
Number unobtainable tone                        102
Offering tone                                   103
Permanent signal tone                           104
Preemption tone                                 105
Queue tone                                      106
Refusal tone                                    107
Route tone                                      108
Valid tone                                      109
Waiting tone                                    110
Warning tone (end of period)                    111
Warning Tone (PIP tone)                         112

Table 5: Country-specific Line events(Payload type) (http://tools.ietf.org/html/rfc2833#section-3.14)

참조 링크

DTMF 방식에 대한 전반적 이해를 위한 링크
http://gunsystems.egloos.com/10280733

VoIP폰에 대한 테스트 결과
http://www.voiceportal.co.kr/696

Event에 대한 설명을 참고하면 좋음
http://nogada2.egloos.com/1443545

SIP 분석
http://cdral.tistory.com/478


http://www.newbroad.co.kr/public_html/index.php?module=Board&action=SiteBoard&iBrdNo=3&sMode=SELECT_FORM


이올린에 북마크하기
2010/04/11 23:56 2010/04/11 23:56
1 2 3 4 5 6 7 8 9 ... 104