1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sock !=-1) // Configuration //
{ memset((char *)&sinip, 0, sizeof(sinip));
sinip.sin_addr.s_addr = inet_addr("192.168.1.4");//sin.sin_addr.s_addr = htonl(INADDR_ANY);
sinip.sin_family = AF_INET; // Protocole(TCP/IP)
sinip.sin_port = htons(PORT); // Listage du port
sock_err = bind(sock, (SOCKADDR*)&sinip, sizeof(sinip));
}
if (sock_err==-1){if (pass==0){printf("La socket est pas encore connecté \n");pass=+1;}; connectsock=0;}
else{printf("La socket est maintenant ouverte en mode UDP \n");connectsock=1;}
while(1)
{
int nb_octet = recvfrom(sock, buffer, sizeof(buffer), 0, (SOCKADDR*)&sinip, &fromlen); //reception de la data dans buffer
// printf("buffer= %s \n",buffer);
// printf("nb oct = %d \n",nb_octet);
char *dataM_X = rech(buffer,"<M_X>");
double M_X = atof(dataM_X);
ect ..... ect....
if (selectionsujet==1)
{
printf("choix du sujet a configuré de 1 à 3\n");
scanf("%d",&choix);
printf("Entrez dist focus en mm\n");// futur input
scanf("%d",&distfocus);
nb_octet = recvfrom(sock, buffer, sizeof(buffer), 0, (SOCKADDR*)&sinip, &fromlen); //reception de la data dans buffer
printf("nb oct = %d \n",nb_octet);
ect... ect....
}
} |
Partager