类似于局域网游戏服务器查找,象魔兽,当一台机器创建一个游戏后(姑且称为服务器),其他的机器(客户端)就可以查看到,我想应该是客户端广播一个查询报文,服务器在收到此报文后给出回告。我现在不是很清楚到底如何控制这个查询报文的接收群体,是否 以*.*.*.255 方式广播就表示只有IP前三段相同的机器才能收到,而以 255.255.255.255方式广播就可以让更多的机器收到(坦白说,我还没有试过255.255.255.255方式能否广播成功),或者怎样才能只让出现在网上邻居里整个网络(不同工作组,我想它们的IP应该是可以四段都不同)的机器收到。
请高手指点。

解决方案 »

  1.   

    windows 是怎么实现整个网络机器查找的?我是否可以利用其结果?
      

  2.   

    BOOL WINAPI EnumerateFunc(HWND hwnd, 
                              HDC hdc, 
                              LPNETRESOURCE lpnr)

      DWORD dwResult, dwResultEnum;
      HANDLE hEnum;
      DWORD cbBuffer = 16384;      // 16K is a good size
      DWORD cEntries = -1;         // enumerate all possible entries
      LPNETRESOURCE lpnrLocal;     // pointer to enumerated structures
      DWORD i;
      //
      // Call the WNetOpenEnum function to begin the enumeration.
      //
      dwResult = WNetOpenEnum(RESOURCE_GLOBALNET, // all network resources
                              RESOURCETYPE_ANY,   // all resources
                              0,        // enumerate all resources
                              lpnr,     // NULL first time the function is called
                              &hEnum);  // handle to the resource  if (dwResult != NO_ERROR)
      {  
        //
        // Process errors with an application-defined error handler.
        //
        NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
        return FALSE;
      }
      //
      // Call the GlobalAlloc function to allocate resources.
      //
      lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
      
      do
      {  
        //
        // Initialize the buffer.
        //
        ZeroMemory(lpnrLocal, cbBuffer);
        //
        // Call the WNetEnumResource function to continue
        //  the enumeration.
        //
        dwResultEnum = WNetEnumResource(hEnum,      // resource handle
                                        &cEntries,  // defined locally as -1
                                        lpnrLocal,  // LPNETRESOURCE
                                        &cbBuffer); // buffer size
        //
        // If the call succeeds, loop through the structures.
        //
        if (dwResultEnum == NO_ERROR)
        {
          for(i = 0; i < cEntries; i++)
          {
            // Call an application-defined function to
            //  display the contents of the NETRESOURCE structures.
            //
            DisplayStruct(hdc, &lpnrLocal[i]);        // If the NETRESOURCE structure represents a container resource, 
            //  call the EnumerateFunc function recursively.        if(RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage
                                           & RESOURCEUSAGE_CONTAINER))
              if(!EnumerateFunc(hwnd, hdc, &lpnrLocal[i]))
                TextOut(hdc, 10, 10, "EnumerateFunc returned FALSE.", 29);
          }
        }
        // Process errors.
        //
        else if (dwResultEnum != ERROR_NO_MORE_ITEMS)
        {
          NetErrorHandler(hwnd, dwResultEnum, (LPSTR)"WNetEnumResource");
          break;
        }
      }
      //
      // End do.
      //
      while(dwResultEnum != ERROR_NO_MORE_ITEMS);
      //
      // Call the GlobalFree function to free the memory.
      //
      GlobalFree((HGLOBAL)lpnrLocal);
      //
      // Call WNetCloseEnum to end the enumeration.
      //
      dwResult = WNetCloseEnum(hEnum);
      
      if(dwResult != NO_ERROR)
      { 
        //
        // Process errors.
        //
        NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCloseEnum");
        return FALSE;
      }  return TRUE;
    }
      

  3.   

    可以用 WNetOpenEnum 和 WNetEnumResource 获取网上邻居里整个网络的机器信息,然后逐一进行查找。
      

  4.   

    本网段内可以用WNetEnumServer查找
      

  5.   

    回computerjjk (天才姜师不哭) 
    1.局域网游戏只能在本网段内玩吧?
    2.“不同工作组,我想它们的IP应该是可以四段都不同”这句话可能有点问题。一个网段内可以有很多不同的工作组。但是IP四段都不同的机器不会在同一个网段,你也不能和他们玩游戏。