UPD broadcast packets

Now think of that client and server do not know under the premise of IP client server can find some say UDP send broadcast packets but achieved their own didn't realize, which are examples.

Started by Dave at December 14, 2016 - 5:32 AM

//Part of the code!

struct addrinfo hints, *res, *ressave;
bzero(&hints, sizeof(struct addrinfo));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
return -1;
ressave = res;
do {
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd <0)
continue;
if (bind(sockfd, res->ai_addr, res->ai_addrlen) == 0)
break;
close(sockfd);
} while ( (res = res->ai_next) != NULL);

Posted by Moses at December 16, 2016 - 5:56 AM

BC:=True;
SetSockOpt(BcSocket,SOL_SOCKET,SO_BROADCAST,PChar(@BC),SizeOf(BC)); //Changes to the broadcasting 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));

Posted by Nicole at December 22, 2016 - 6:05 AM


procedure UDPBroadcasting();
var
RxBuf:TIdBytes;
begin
RxBuf := Idglobal.RawToBytes(DM.uUDPBroadcastingBuf, SizeOf (DM.uUDPBroadcastingBuf));
idpclnt.SendBuffer('50.255.255.255',8888,RxBuf);
end;

Posted by Grover at January 04, 2017 - 8:12 AM

IdUDPServer1->Broadcast("hello every",5000);
Control the use of direct broadcast messages on it

An IdUDPServer1 control in the udpRead event

Posted by Phyllis at January 06, 2017 - 6:41 AM

UDP broadcasts, but does not guarantee an end to receive.
The experiment found that only two individuals, client's case, there seem to be 50% messages are missing!
Is not the mistake?

Posted by Grace at January 11, 2017 - 7:26 AM