我想用vc对80端口传来的数据进行显示并处理,多谢!!!

解决方案 »

  1.   

    这个函数你可能适合,是检查网址是否可以访问的函数int CheckURL(CString strAddress)
    {
    CInternetSession session(_T("Check URL"));
    CHttpConnection *pServer = NULL;
    CHttpFile *pFile = NULL;
    CString m_strContent;
    int nRetValue = 1; m_strContent.Empty();
    try
    {
    CString strServer;
    CString strObject;
    INTERNET_PORT nPort;
    DWORD dwServiceType; if(!AfxParseURL(strAddress, dwServiceType, strServer, strObject, nPort) || dwServiceType != INTERNET_SERVICE_HTTP)
    {
    nRetValue = 0;
    return nRetValue;
    } pServer = session.GetHttpConnection(strServer, nPort); pFile = pServer->OpenRequest(1, strObject, NULL, 1, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT);
    pFile->AddRequestHeaders(_T("Check URL"));
    pFile->SendRequest(); DWORD dwRet;
    pFile->QueryInfoStatusCode(dwRet);
    while(dwRet == HTTP_STATUS_DENIED)
    {
    DWORD dwPrompt;
    dwPrompt = pFile->ErrorDlg(NULL, 
    ERROR_INTERNET_INCORRECT_PASSWORD,
    FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
    NULL); if(dwPrompt != ERROR_INTERNET_FORCE_RETRY)
    {
    nRetValue = 0;
    goto end;
    }
    pFile->SendRequest();
    pFile->QueryInfoStatusCode(dwRet);
    } CString strNewLocation;
    pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
    CString line;
    while(pFile->ReadString(line))
    m_strContent += line + "\r\n"; if((m_strContent.Find("<title>无法找到网页</title>") > 0) || (m_strContent.Find("<title>The page cannot be found</title>") > 0))
    {
    nRetValue = 0;
    m_strContent.Empty();
    } pFile->Close();
    pServer->Close();
    }
    catch(CInternetException *pEx)
    {
    nRetValue = 0;
    pEx->Delete();
    }end:
    if(pFile != NULL)
    {
    delete pFile;
    pFile = NULL;
    }
    if(pServer != NULL)
    {
    delete pServer;
    pServer = NULL;
    }
    session.Close();

    return nRetValue;
    }
      

  2.   

    CSocket socke,secondSocket;
    CSocket socket.Create(80,SOCK_STREAM);
    socket.Listen(5);
    while(true){
      socket.Accept(secondSocket);
      //开线程
    }
      

  3.   

    楼上的老兄已经为你写了时刻侦听80 Port的代码
    最后附加一句:接收信息----〉
    socket.Receive(&StreamFileInfo,sizeof(SOCKET_STREAM_FILE_INFO));
    或使用ReceiveFrom()函数
      

  4.   

    去看一下:
    http://www.csdn.net/expert/topic/879/879041.xml?temp=.4701807
    其中可能有你用的