procedure gb;//发送广播
var  mystream:tmemorystream;
begin
nmudp1.ReportLevel:=status_basic;//?
nmudp1.RemoteHost :="192.168.0.255";//广播就是发送地址是c类*.*.*.255的,b类是*.*.255.255
mystream:=tmemorystream.Create;
try
   mystream.Write(tmpstr[1],length(tmpstr));
   nmudp1.SendStream(mystream);
finally
   mystream.Free;
end;
end;

解决方案 »

  1.   

    在送你
    procedure gbIp;//取得广播的ip地址,比如本机是192.168.0.1,这个函数得到192.168.0.255
    var
      i,j,iHead:Integer;
      sHead,s:String;
      ai:array [1..3] of integer;
    begin
    with form1 do
    begin
    LocalIP:=Powersock1.LocalIP;//本机ip
      j:=1;
      //取出。的位置
      for i:=0 to Length(LocalIP) do
      begin
        if LocalIP[i]='.' then
        begin
          ai[j]:=i;
          Inc(j);
        end;
        if j>3 then break;
      end;
      //shead为ip第一段
      sHead:=Copy(LocalIp,1,ai[1]-1);
      iHead:=StrToInt(sHead);
      if iHead<128 then  //A类网
        begin
          BroadCastIP:=sHead+'.255.255.255';//a类网的广播ip
        end
      else
        begin
          if iHead<192 then //B类网
             begin
               s:=Copy(LocalIP,1,ai[2]-1);
               BroadCastIP:=s+'.255.255';//b类网的广播ip
             end
          else  //C类网
              begin
                 s:=Copy(LocalIP,1,ai[3]-1);
                 BroadCastIP:=s+'.255';//c类网的广播ip
              end;
        end;
    end;
    end;