Hello. I need automatically get address of server. I want to send broadcast request from client and dsp will answer.
I tried to do the same on two PC. Then I tried to send broadcast request from TMS to PC. It works.
But I can not receive broadcast message on TMS. There is my piece of code.
fdOpenSession(TaskSelf());
SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
char buff[100] = {0xFF, 0xFF, 0xFF, 0xFF};
sockaddr_in addr, remAddr;
bzero( &addr, sizeof(struct sockaddr_in));
bzero( &remAddr, sizeof(struct sockaddr_in));
addr.sin_port = htons(10222);
addr.sin_family = AF_INET;
if (bind(sock, (PSA)&addr, sizeof(addr)) < 0){
printf("Bind error: %d\n", fdError());
}
timeval timeout;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) );
setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );
int r = recvfrom(sock, (void*)buff, 4, MSG_WAITALL, (PSA)&remAddr, &len); //TIMEOUT
What can I do incorrect? Thank a lot