<P>지금 회사에서 PDA 프로그램을 만들고 있습니다</P> <P>배송용 PDA 인데 3G 네트워크가 자꾸 끊겨서</P> <P>Ras 로 자동연결하도록 개발 했습니다.</P> <P>3G가 끊겼을시 인터넷은 정상적으로 연결이 되는데</P> <P>문제가 HttpSendRequest 이 부분에서 1분에서 3분까지 멈춰있는 경우가 많아요</P> <P>정상적으로 될때도 있는데 아무래도 인터넷은 연결됐지만</P> <P>프로그램에서 멈춰있으니 기다릴수 밖에 없는데</P> <P>1분에서 3분은 너무 길구요ㅜ 좀 찾아보니깐 버그라고 하던데..</P> <P> InternetSetOption 이 작동되지 않는 버그라고 하더라구요.</P> <P>Thread 만들어서 timeout 작동되게 하면 된다고 하던데</P> <P>인터넷에 찾아봐도 다 VC++ 밖에 없어서 ㅜㅜ evc로 개발하다보니</P> <P>적용을 못하겠네요. 그럼 함수 호출 부분 소스 보여드리겠습니다.</P> <P>좀 도와주시면 감사하겠습니다</P> <P> </P> <P> CString CWMSonPDAApp::NetRequest(CString strSubUrl, BOOL isRas)<BR>{<BR> if(isRas == TRUE)<BR> {<BR> RasSync();<BR> }<BR> BOOL bRet = FALSE;</P> <P> BeginWaitCursor();</P> <P> </P> <P> HINTERNET hSession = NULL;<BR> hSession = InternetOpen(_T("ChegimPDA"), PRE_CONFIG_INTERNET_ACCESS, NULL, INTERNET_INVALID_PORT_NUMBER, 0);</P> <P> DWORD timeout = 5000;<BR> InternetSetOption(hSession, INTERNET_OPTION_MAX_CONNS_PER_SERVER, &timeout, sizeof(timeout));</P> <P> if (hSession == NULL)<BR> {<BR> AfxMessageBox(_T("InternetOpen 실패") );<BR> InternetCloseHandle(hSession);<BR> return _T("");<BR> }</P> <P> HINTERNET hDomain = NULL;<BR> hDomain = InternetConnect(hSession, m_strDomain, m_nInetPort, _T(""), _T(""), INTERNET_SERVICE_HTTP, 0, (DWORD) 0);<BR> </P> <P> if (hDomain == NULL)<BR> {<BR> AfxMessageBox(_T("InternetConnect 실패") );<BR> InternetCloseHandle(hDomain);<BR> return _T("");<BR> }</P> <P> HINTERNET hRequest = NULL;<BR> hRequest = HttpOpenRequest(hDomain, _T("POST"), strSubUrl, NULL, NULL, NULL, INTERNET_FLAG_DONT_CACHE, 0);</P> <P> if( hRequest == NULL)<BR> {<BR> AfxMessageBox( _T("오픈실패") );<BR> }</P> <P> DWORD dwConnectionTypes;<BR> if(InternetGetConnectedState(&dwConnectionTypes, 0)) // 정상적으로 검사됨 <BR> {<BR> if((dwConnectionTypes & INTERNET_CONNECTION_OFFLINE) != 0){<BR> // AfxMessageBox( _T("오프라인 상태 ") );<BR> EndWaitCursor();<BR> return _T("");<BR> }<BR> }else<BR> {</P> <P><BR> }</P> <P> BOOL bSucc = HttpSendRequest(hRequest, NULL, 0, NULL, 0); </P> <P><BR> if(!bSucc )<BR> {<BR> AfxMessageBox( _T("접속이 끊어짐 ") );<BR> EndWaitCursor();<BR> InternetCloseHandle (hRequest); <BR> m_hSession= NULL;<BR> hRequest = NULL;<BR> return _T("");<BR> }</P> <P><BR> </P> <P> char *databuff = NULL;<BR> char *tempbuff = NULL;<BR> <BR> CString strWEBPage = _T("");<BR> char buff[1026];<BR> DWORD dwRetSize = 0;<BR> DWORD dwTotlaSize = 0;</P> <P> memset(buff, 0, 1026);<BR> <BR> while( InternetReadFile(hRequest, &buff[0], 1024, &dwRetSize ) )<BR> {<BR> if( dwRetSize == 0)<BR> break;</P> <P> dwTotlaSize += dwRetSize;<BR> <BR> if( databuff == NULL )<BR> {<BR> databuff = (char*) malloc(dwRetSize + 1);<BR> <BR> memcpy(databuff, &buff[0], dwRetSize);<BR> }<BR> else<BR> { <BR> if( tempbuff != NULL )<BR> {<BR> free(tempbuff);<BR> tempbuff = NULL;<BR> }<BR> <BR> tempbuff = (char*) malloc(dwTotlaSize + 1);<BR> memset(tempbuff, 0, dwTotlaSize + 1);<BR> <BR> memcpy(tempbuff, databuff, dwTotlaSize - dwRetSize );<BR> memcpy(&tempbuff[dwTotlaSize - dwRetSize], &buff[0], dwRetSize);<BR> <BR> if( databuff != NULL )<BR> {<BR> free(databuff);<BR> databuff = NULL;<BR> <BR> databuff = (char*) malloc(dwTotlaSize + 1);<BR> memset(databuff, 0, dwTotlaSize + 1);<BR> <BR> memcpy(databuff, tempbuff, dwTotlaSize + 1); <BR> } <BR> } <BR> memset(buff, 0, 1026); <BR> }</P> <P> if( dwTotlaSize == 0 )<BR> {<BR> EndWaitCursor();<BR> return _T("");<BR> }</P> <P> databuff[dwTotlaSize] = '\0';<BR> strWEBPage += databuff;</P> <P> if( tempbuff != NULL )<BR> {<BR> free(tempbuff);<BR> tempbuff = NULL;<BR> }<BR> <BR> if( databuff != NULL )<BR> {<BR> free(databuff);<BR> databuff = NULL;<BR> }</P> <P> InternetCloseHandle(hRequest);<BR> hRequest = NULL;</P> <P><BR> strWEBPage.TrimLeft();<BR> strWEBPage.TrimRight();</P> <P> EndWaitCursor();<BR> return strWEBPage;<BR>}</P>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.