MultiCast Messages to multiple clients on the same machine

后端 未结 5 1819
醉话见心
醉话见心 2021-02-14 10:34

Im trying to write a server/service that broadcasts a message on the lan ever second or so, Kind of like a service discovery.

The message needs to be rece

5条回答
  •  悲哀的现实
    2021-02-14 10:50

    with the hint from shf301, this is the code i got it to work with

    i created a new TIdIPMCastClient

     TIdReUseIPMCastClient = class(TIdIPMCastClient)
      private
        procedure SetReUseAddr(InBinding: TIdSocketHandle; const Value: boolean);
      protected
        function GetBinding: TIdSocketHandle; override;
      public
      end;
    

    added the Procedure

    procedure TIdReUseIPMCastClient.SetReUseAddr(InBinding: TIdSocketHandle; const Value: boolean);
    var
      tempi: integer;
    begin
      if Assigned(InBinding) and InBinding.HandleAllocated then
        begin
        tempi := iif(Value, 1, 0);
        InBinding.SetSockOpt(Id_SOL_SOCKET, Id_SO_REUSEADDR, PChar(@tempi), SizeOf(tempi));
        end;
    end;
    

    copied the GetBinding code from TIdIPMCastClient, and added the SetReUseAddr before the bind

      Bindings[i].AllocateSocket(Id_SOCK_DGRAM);
      SetReUseAddr(Bindings[i], True);
      Bindings[i].Bind;
    

提交回复
热议问题