23
LES SOCKETS

Atelier 10

Embed Size (px)

Citation preview

Page 1: Atelier 10

LES SOCKETS

Page 2: Atelier 10

PLAN :

Page 3: Atelier 10

INTRODUCTION

Page 4: Atelier 10

C ’EST QUOI LES SOCKET

Page 5: Atelier 10

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 .

Page 6: Atelier 10

MODE CONNECTÉ

Page 7: Atelier 10

MODE NON CONNECTÉ

Page 8: Atelier 10

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

Page 9: Atelier 10

DOMAINE DE COMMUNICATION

UNIX INTERNET DECNET ……..

Le domaine INTERNERT spécifier par AF_INET

Page 10: Atelier 10

PROTOCOLE

SOCK_STREAM TCP

SOCK_DGRAM UDP

SOCK_RAW ICMP

Page 11: Atelier 10

ALGORITHME D’UN SERVEUR EN MODE CONNECTÉ

Serveur Client

Page 12: Atelier 10

ALGORITHME D’UN CLIENT EN MODE NON

CONNECTÉ

ClientServeur

Page 13: Atelier 10

PRIMITIVES

Page 14: Atelier 10

LA CRÉATION D’UNE SOCKET

int socket(int domain, int type, int protocol);

Exemple : s=socket(PF_INET,SOCK_DGRAM,0);

Page 15: Atelier 10

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);

}

Page 16: Atelier 10

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);

}

Page 17: Atelier 10

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);

}

Page 18: Atelier 10

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);

}

Page 19: Atelier 10

TRANSMISSION ET RECEPTION DES DONNEES

EN MODE CONNECTE

int write(int s, char * buf, int nbyte);

int read(int s, char * buf, int nbyte);

Page 20: Atelier 10

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);

Page 21: Atelier 10

FERMETURE D’UNE SOCKET

Int close(int sock);

Page 22: Atelier 10

Merci de votre attention

Page 23: Atelier 10

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