feat(puit): v1 sans boucle
This commit is contained in:
parent
98bfb60ffc
commit
10a15c0c43
1 changed files with 30 additions and 2 deletions
32
tsock_v1.c
32
tsock_v1.c
|
@ -113,11 +113,11 @@ int main (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (udp==1){
|
||||
// Creation du socket local
|
||||
int sock= socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
if (source==1) {
|
||||
|
||||
// Creation du socket local
|
||||
int sock= socket(AF_INET,SOCK_DGRAM,0);
|
||||
|
||||
|
||||
// Creation de l'adresse du socket distant
|
||||
|
@ -154,6 +154,34 @@ int main (int argc, char **argv)
|
|||
|
||||
else {
|
||||
|
||||
|
||||
// Creation de l'adresse du socket distant
|
||||
struct sockaddr_in adr_locale;
|
||||
int longueur_adr_locale = sizeof(adr_locale);
|
||||
|
||||
int longueur_message = BASE_SIZE;
|
||||
|
||||
memset((char *)& adr_locale, 0, sizeof(adr_locale)) ;
|
||||
|
||||
adr_locale.sin_family=AF_INET;
|
||||
adr_locale.sin_port=port;
|
||||
adr_locale.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
// Bind the local socket to any local address (ie any available interface)
|
||||
if (bind(sock, (struct sockaddr *) &adr_locale, longueur_adr_locale) == -1) {
|
||||
printf("failed to bind\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Receive a single message because we are lazy
|
||||
recvfrom(sock, message, longueur_message, 0, NULL, NULL);
|
||||
|
||||
// Afficher notre seule et unique triste message
|
||||
afficher_message(message, longueur_message);
|
||||
|
||||
exit(0);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue