1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| // Emetteur qui envoie au récepteur
strcpy(buffer, "bienvenue au pays des glaces");
inet_aton("10.192.52.1", &(address.sin_addr));
address.sin_port = htons(2000);
address.sin_family = AF_INET;
sock = socket(AF_INET, SOCK_DGRAM,0);
bind(sock, adresse, sizeof(struct sockaddr_in));
sendto(sock,buffer,length,0,addrOutput,&addrOutput);
// Récepteur qui écoute tout le monde
inet_aton("0.0.0.0", &(address.sin_addr));
address.sin_port = htons(2000);
address.sin_family = AF_INET;
sock = socket(AF_INET, SOCK_DGRAM,0);
bind(sock, adresse, sizeof(struct sockaddr_in));
recvfrom(sock,buffer, length,0,addrInput,&addrInputLength); |
Partager