Home > Software engineering >  Do a radio SOCKET anyway don't send data! Caught tools all could not see the packet
Do a radio SOCKET anyway don't send data! Caught tools all could not see the packet

Time:10-11

 int _BROAD (int tm, int con, char ADR [16], char MSG [16])//how many milliseconds, every X times, what address, send content; 
{
int i=0; Char * MSG. MSG=MSG;
BOOL fBroadcast=TRUE;
WORD wVersionRequested;
WVersionRequested=MAKEWORD (2, 2); Int err;
WSADATA WSADATA;
If (=="X" (ADR)
{
SOCKADDR_IN broad;
Bool fb=true;
The SOCKET Serv=SOCKET (AF_INET, SOCK_DGRAM, IPPROTO_UDP);//create the receiving set of words
The setsockopt (Serv, SOL_SOCKET, SO_BROADCAST, (CHAR *) & amp; Fb, sizeof (BOOL));
Broad. Sin_family=AF_INET;
Broad. Sin_addr. S_addr=
//broad sin_addr. S_un. S_addr=htonl (INADDR_BROADCAST);
Broad. Sin_port=htons (5333);
Bind (Serv, (SOCKADDR *) & amp; Broad, sizeof (broad));
SOCKADDR_IN Sevr;
Sevr. Sin_family=AF_INET;
Sevr. Sin_addr. S_addr=inet_addr (" 192.168.1.233 ");
Char g [30];
While (I!=con)
{
MessageBox (NULL, TEXT (" Xx "), TEXT (" GC "), 0).
//sendto (bro, MSG, lstrlen (MSG), 0, (SOCKADDR *) & amp; Broad, sizeof (BOOL));
Sendto (Serv, MSG, err, 0, (SOCKADDR *) & amp; Broad, sizeof (broad));
//i++;
//MessageBox (NULL, TEXT (" broadcast "), TEXT (" GC "), 0).
Sleep (tm);
}
Closesocket (Serv);
JSQ=false;
}
The _endthread ();
return 0;
}
The main ()
{
_beginthread (void) (*) (void *) _BROAD (500, 5, "X", "?" ), and 0, t);
}

CodePudding user response:

Anecdotal hearsay, need administrator privileges,

CodePudding user response:

Check to see if the API returns the right, the second is to send a packet format is correct, is blocked by a firewall

CodePudding user response:

1. The if (ADR=="X")===="a slip of the pen or code that is written?
2. Bind (Serv, (SOCKADDR *) & amp; Broad, sizeof (broad)); Before, what did you write there? Let others help you find a BUG, it somehow code should also be neat and specification,
3. The full text, I didn't see you have to send broadcast data, even I doubt you bind all wrong, look for the example of a UDP communication code, knock, compile operation, in to this problem,
  • Related