LES SOCKETS
PLAN :
INTRODUCTION
C ’EST QUOI LES SOCKET
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 .
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É




                           Client
  Serveur
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

Atelier 10

  • 1.
  • 2.
  • 3.
  • 4.
    C ’EST QUOILES SOCKET
  • 5.
    SOCKET • Lessockets 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 .
  • 6.
  • 7.
  • 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
  • 9.
    DOMAINE DE COMMUNICATION UNIXINTERNET DECNET …….. Le domaine INTERNERT spécifier par AF_INET
  • 10.
    PROTOCOLE SOCK_STREAM TCP SOCK_DGRAM UDP SOCK_RAW ICMP
  • 11.
    ALGORITHME D’UN SERVEUREN MODE CONNECTÉ Serveur Client
  • 12.
    ALGORITHME D’UN CLIENTEN MODE NON CONNECTÉ Client Serveur
  • 13.
  • 14.
    LA CRÉATION D’UNESOCKET int socket(int domain, int type, int protocol); Exemple : s=socket(PF_INET,SOCK_DGRAM,0);
  • 15.
    RENSEIGNEMENT DE LASOCKET 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 LASOCKET 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 SERVEURA 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’ENSEMBLEDES 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 RECEPTIONDES DONNEES EN MODE CONNECTE int write(int s, char * buf, int nbyte); int read(int s, char * buf, int nbyte);
  • 20.
    TRANSMISSION ET RECEPTIONDES 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);
  • 21.
    FERMETURE D’UNE SOCKET Int close(int sock);
  • 22.
    Merci de votre attention 
  • 23.
    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