CodePudding user response:
//code!
Res struct addrinfo hints, * and * ressave;
Bzero (& amp; Hints, sizeof (struct addrinfo));
Hints. Ai_flags=AI_PASSIVE;
Hints. Ai_family=AF_INET;
Hints. Ai_socktype=SOCK_DGRAM;
If ((n=getaddrinfo (host, serv, & amp; Hints, & amp; Res))!=0)
The return - 1;
Ressave=res;
Do {
Sockfd=socket (res - & gt; Ai_family, res - & gt; Ai_socktype, res - & gt; Ai_protocol);
If (sockfd & lt; 0)
continue;
If (bind (sockfd, res - & gt; Ai_addr, res - & gt; Ai_addrlen)==0)
break;
Close (sockfd);
} while ((res=res - & gt; Ai_next)!=NULL);
CodePudding user response:
BC:=True;The SetSockOpt (BcSocket, SOL_SOCKET, SO_BROADCAST, PChar (@ BC), SizeOf (BC));//to broadcast state
SerAddr. Sin_family:=AF_INET;
SerAddr. Sin_addr. S_addr:=inet_addr (' 255.255.255.255);
SerAddr. Sin_port:=htons (UDP_LIS_PORT);
SendTo (BcSocket, Buffer Size, 0, SerAddr, SizeOf (TSockAddr));
CodePudding user response:
Procedure UDPBroadcasting ();
Var
RxBuf: TIdBytes;
The begin
RxBuf:=Idglobal RawToBytes (DM) uUDPBroadcastingBuf, SizeOf (DM. UUDPBroadcastingBuf));
Idpclnt. SendBuffer (' 50.255.255.255 ', 8888, RxBuf);
end;
CodePudding user response:
IdUDPServer1 - & gt; Broadcast (" hello every ", 5000);Use controls directly it is ok to send broadcast messages
In the event of an udpRead accept with IdUDPServer1 controls
CodePudding user response:
UDP broadcast, but does not guarantee the receiver can receive,Only client personal experiment found that the two cases, seems to have 50% of the message is missing!
What went wrong?
CodePudding user response: