Multicast on Windows lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- iwilson · 2013-01-09 18:28 Hey, I can't seem to get this to work... yet I have no issues on Linux. The below code works perfectly fine on my Linux machine but not on any Windows. Firewall is disabled, 10.0.0.3 is a NIC, 224.126.126.126 is a valid multicast address receiving messages. Code: [Select]program project1; {$mode objfpc}{$H+} uses   Classes, Sockets,   {$IFDEF MSWINDOWS}   Windows,   Winsock,   {$ELSE}   BaseUnix,   UnixType,   {$ENDIF}    Sysutils; type TIP_mreq = packed record     imr_multiaddr: in_addr;     // IP multicast address of group     imr_interface: in_addr;     // local IP address of interfacetype   end; var   ASock_Addr : SockAddr_In;   FSocket    : LongInt;   ipmreq     : TIP_mreq;   MasterFD,   TempFD     : TFDSet;   TestInt    : Integer;   Timeout    : TTimeVal; begin   FSocket := fpSocket(AF_INET, LongInt(SOCK_DGRAM), 0);   if (FSocket > 0) then   begin     fpSetSockOpt(FSocket, SOL_SOCKET, SO_REUSEADDR, PChar('True'), Length('True'));     FillByte(ASock_Addr, SizeOf(SockAddr_In), 0);     ASock_Addr.sin_family      := AF_INET;     ASock_Addr.sin_port        := HtoNS(15510);     ASock_Addr.sin_addr.S_addr := INADDR_ANY;     if (fpbind(FSocket, @ASock_Addr, SizeOf(SockAddr_In)) = 0) then     begin       FillByte(ipmreq, SizeOf(Tip_mreq),0);       ipmreq.imr_multiaddr.s_addr := StrToNetAddr('224.126.126.126').s_addr;       ipmreq.imr_interface.s_addr := StrToNetAddr('10.0.0.3').s_addr;       fpSetsockOpt(FSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP,  @ipmreq, SizeOf(ipmreq));       {$IFDEF MSWINDOWS}           FD_SET(FSocket, MasterFD);       {$ELSE}           fpFD_SET(FSocket, MasterFD);       {$ENDIF}       while (true) do       begin         TempFD := MasterFD;         TimeOut.tv_sec  := 0;         TimeOut.tv_usec := 20;         {$IFDEF MSWINDOWS}            TestInt := Select(FSocket, @TempFD, NIL, NIL, @TimeOut);         {$ELSE}            TestInt := fpSelect(FSocket, @TempFD, NIL, NIL, @TimeOut);         {$ENDIF}         if (TestInt > 0) then         begin           TestInt := 0;         end;         Sleep(1);       end;     end;   end; end. Any tips would be greatly appreciated. Thanks. EDIT: I should have been more clear, everything works other than Select never being > on 0 (not receiving messages). It stays within the loop. ---------------------------------------------------------------------- iwilson · 2013-01-09 18:45 I would like to add that I just got this to work on a Windows XP VM running on my host machine that cannot do the same (Windows 7). Looks like this may be a Windows 7 (vista maybe) issue only. Has anyone successfully pulled this off on 7? ---------------------------------------------------------------------- Zoran · 2013-01-09 22:19 I can't see break in your while loop. ---------------------------------------------------------------------- iwilson · 2013-04-03 15:01 bump, still having the same issue. ---------------------------------------------------------------------- iwilson · 2013-04-04 15:55 The answer is to use the Winsock calls for Bind and SetSockOpt on Windows 7 and up. This isn't necessary on XP. ---------------------------------------------------------------------- BigChimp · 2013-04-04 19:52 iwilson, Thanks for posting the solution! (And sorry I couldn't help)