Upload
med-amine-talhaoui
View
671
Download
0
Embed Size (px)
Citation preview
LES SOCKETS
PLAN :
INTRODUCTION
C ’EST QUOI LES SOCKET
SOCKET
application application
socket
• Les sockets consistent une interface permettant aux applications de
communiquer soit à travers des réseaux soit en locale .
• Le terme socket désigne aussi un canal de communication par la quel
un processus peut envoyer ou recevoir des données .
MODE CONNECTÉ
MODE NON CONNECTÉ
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
DOMAINE DE COMMUNICATION
UNIX INTERNET DECNET ……..
Le domaine INTERNERT spécifier par AF_INET
PROTOCOLE
SOCK_STREAM TCP
SOCK_DGRAM UDP
SOCK_RAW ICMP
ALGORITHME D’UN SERVEUR EN MODE CONNECTÉ
Serveur Client
ALGORITHME D’UN CLIENT EN MODE NON
CONNECTÉ
ClientServeur
PRIMITIVES
LA CRÉATION D’UNE SOCKET
int socket(int domain, int type, int protocol);
Exemple : s=socket(PF_INET,SOCK_DGRAM,0);
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);
}
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);
}
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);
}
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);
}
TRANSMISSION ET RECEPTION DES DONNEES
EN MODE CONNECTE
int write(int s, char * buf, int nbyte);
int read(int s, char * buf, int nbyte);
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);
FERMETURE D’UNE SOCKET
Int close(int sock);
Merci de votre attention
CETTE ATELIER EST:
RÉALISÉ PAR: ENCADRÉ PAR:
• ELOUALIDI Soufiane
• ELKASMI Hicham
• BASSKAR Loubna Mme F.BENABBOU
• OUYAAZ Hasnaa
• SLIMANI Zakia
• MOUKHLISS Loubna
• DOUMIRI Jihad
• BOUNIT Widad