如题.

解决方案 »

  1.   

    因为我的导师让我做corba啊,要很深入的研究socket才行.我最近看msdn头疼死了。
    设置这个结构不是能更精确的建立socket吗?
      

  2.   

    寒。你说起corba我就背心发凉,这次考中间件差点挂了..-_-b其实 WSAEnumProtocols 可以获得本机可用的传输协议里面会返回一个 WSAPROTOCOL_INFO 结构,你可以研究一下^_^
      

  3.   

    Use the WSAPROTOCOL_INFO Structure to Create a Socket
    if (WSAStartup(MAKEWORD(2,2), &WSAData))
          printf("WSAStartup %d", WSAGetLastError());
       else
          {
          // First, have WSAEnumProtocols tell you how big a buffer you need.
          nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
          if (SOCKET_ERROR != nRet)
             printf("WSAEnumProtocols: should not have succeeded\n");
          else if (WSAENOBUFS != (dwErr = WSAGetLastError()))
             // WSAEnumProtocols failed for some reason not relating to buffer
             // size - also odd.
             printf("WSAEnumProtocols(1): %d\n", WSAGetLastError());
          else
             {
             // WSAEnumProtocols failed for the "expected" reason. Therefore,
             // you need to allocate a buffer of the appropriate size.
             lpProtocolBuf = (WSAPROTOCOL_INFO *)malloc(dwBufLen);
             if (lpProtocolBuf)
                {
                // Now you can call WSAEnumProtocols again with the expectation
                // that it will succeed because you have allocated a big enough
                // buffer.
                nRet = WSAEnumProtocols(NULL, lpProtocolBuf, &dwBufLen);
                if (SOCKET_ERROR == nRet)
                   printf("WSAEnumProtocols(3): %d\n", WSAGetLastError());
                else
                   {
                   // Loop through protocols, looking for the first service
                   // provider that meets the matching criteria.
                   bProtocolFound = FALSE;
                   for (i=0; i<nRet; i++)
                      {
                      if ((IPPROTO_TCP == lpProtocolBuf[i].iProtocol) &&
                          (XP1_QOS_SUPPORTED == (XP1_QOS_SUPPORTED &
                           lpProtocolBuf[i].dwServiceFlags1)))
                         {
                         bProtocolFound = TRUE;
                         break;
                         }
                      }
                   }
                }
             }
          }
      

  4.   

    PiggyXP,你好,哪个学校的呀,
    我东南的,以后多交流。