Home > Back-end >  Upd broadcast packets
Upd broadcast packets

Time:10-02

Now want to achieve is to the client and server don't know under the premise of IP server client can find someone said using udp send broadcast packets but they realized didn't achieve it, excuse me which have instance to see thank you

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:

reference 5 floor xiaorang reply:
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:

Udp broadcast on a single network card attached to the source code
http://jingyan.baidu.com/article/db55b6099501154ba30a2fc1.html
Udp broadcast on multiple network card attached to the source code
http://jingyan.baidu.com/article/afd8f4de4608af34e286e9f6.html

  • Related