#include #include #include #include #include #include #include #include using namespace std; //*********************************************************************** int main (int argc, char *argv[]) { signed short int sendto_port = 10068; char sendto_eth[] = "168.105.15.189"; struct sockaddr_in sendto_address; sendto_address.sin_family = AF_INET; sendto_address.sin_port = htons(sendto_port); sendto_address.sin_addr.s_addr = inet_addr(sendto_eth); // The for loop gives us 10 chances to try and establish the // command socket...after which we give up trying to send the // command and return a FALSE to the calling function for(int j = 0; j < 20; j++) { for(int i = 0; i < 10 ; i++) { signed short int cmdSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(cmdSocket == -1) usleep(1000); else { // We've connected, send the command to the DSP, close the socket, // and then break out of the loop unsigned char cmd_len = 6; unsigned char cmd[cmd_len]; unsigned int t = time(NULL); cmd[0] = 0xC0; cmd[1] = 0x01; cmd[2] = (unsigned char)(t>>24)&0xFF; cmd[3] = (unsigned char)(t>>16)&0xFF; cmd[4] = (unsigned char)(t>>8)&0xFF; cmd[5] = (unsigned char)(t&0xFF); signed short int errorCode = sendto(cmdSocket, cmd, cmd_len, 0, (struct sockaddr *)&sendto_address, sizeof(sendto_address)); printf("ip: %s ", sendto_eth); printf("port: %d ", sendto_port); printf("time: %d ",t); for(int k = 0; k < cmd_len; k++) printf("%02X",cmd[k]); printf("\n"); close(cmdSocket); break; } } //sleep for 1s before sending out the next time information sleep(1); } return(0); }