5. SOCKET
• Les sockets consistent une interface permettant aux applications de
communiquer soit à travers des réseaux soit en locale .
application application
socket
• Le terme socket désigne aussi un canal de communication par la quel
un processus peut envoyer ou recevoir des données .
8. TYPE DE SOCKET
SOCK_STREAM :
La communication est en Mode connecter
SOCK_DGRAM :
La communication est en non connecter
SOCK_RAW :
Il permet l ’accés a des protocole de bas niveau
14. LA CRÉATION D’UNE SOCKET
int socket(int domain, int type, int protocol);
Exemple : s=socket(PF_INET,SOCK_DGRAM,0);
15. RENSEIGNEMENT DE LA SOCKET AVEC LES
INFORMATIONS LOCALES
int bind(int s, struct sockaddr_in * addsock, int lg_addsock);
Exemple : if (bind(s, &add_sock,sizeof(add_sock)))
{fprintf(stderr,‘‘Echec dans la réalisation du bind(...)’’);
exit(EXIT_BINDING_SOCK);
}
16. RENSEIGNEMENT DE LA SOCKET POUR LE
DESTINATAIRE
lg_dint connect(int s, struct sockaddr_in * dest, int est);
Exemple : if (connect(sock, &addsock, sizeof(addsock)) < 0)
{perror("Echec de lien de socket");
exit(EXIT_ERR_CONNECT_SOCK);
}
17. METTRE LE SERVEUR A L ’ ÉTAT D’ÉCOUTE
int listen(int s, int backlog);
Exemple : if (listen(sock,MAXCONREQ) < 0)
{perror("Echec du listen");
exit(EXIT_ERR_LISTEN);
}
18. DÉFINITION DE L’ENSEMBLE DES CONNEXIONS
ACCEPTABLES
int accept(int s, struct sockaddr_in * from, Int * fromlen);
Exemple : new_sock = accept(s, &add_initiator, &size_add_initiator);
if (new_sock < 0)
{perror("Echec de l'accept");
exit(EXIT_ERR_ACCEPT);
}
19. TRANSMISSION ET RECEPTION DES DONNEES
EN MODE CONNECTE
int write(int s, char * buf, int nbyte);
int read(int s, char * buf, int nbyte);
20. TRANSMISSION ET RECEPTION DES DONNEES
EN MODE NON CONNECTE
int sendto(int s, char * buf, int nbyte, int flag,struct
sockaddr_in * dest, int * destlen);
Int recvfrom(int s, char * buf, int nbyte, int flag,
struct sockaddr_in * dest, int *
destlen);