Translation

English
English French Actions
The first argument is the file descriptor of the socket that we use to perform the communication. ``buf`` is a buffer of length ``len`` containing the bytes to send to the peer. The usage of ``flags`` argument is out of the scope of this section and can be set to 0. ``dest_addr`` is the socket address of the destination to which we want to send the bytes, its length is passed using the ``addrlen`` argument. Le premier argument est le descripteur de fichier de la socket que nous utilisons pour effectuer la communication. ``buf`` est un tampon de longueur ``len`` contenant les octets à envoyer à l'homologue. L'utilisation de l'argument ``flags`` est hors de portée de cette section et peut être mis à 0. ``dest_addr`` est l'adresse de la socket de destination à laquelle nous voulons envoyer les octets, sa longueur est passée en utilisant l'argument ``addrlen`'.
In the following example, a C program is sending the bytes ``'h'``, ``'e'``, ``'l'``, ``'l'`` and ``'o'`` to a remote process located at address ``peer_addr``, using the already created socket ``sock``. Dans l'exemple suivant, un programme C envoie les octets ``'h'``, ``'e'``, ``'l'``, ``'l'`` et ``'o'`` à un processus distant situé à l'adresse ``peer_addr``, en utilisant la socket ``sock`` déjà créée.
As the ``sendto`` function is generic, this function will work correctly independently from the fact that the peer's address is defined as a path on the computer filesystem or a network address. Comme la fonction ``sendto`` est générique, cette fonction fonctionnera correctement indépendamment du fait que l'adresse de l'homologue soit définie comme un chemin sur le système de fichiers de l'ordinateur ou une adresse réseau.
Receiving data from a peer using a socket Recevoir des données d'un pair en utilisant un socket
The following program binds its socket to a given socket address and then waits for receiving new bytes, using the already created socket ``sock``. Le programme suivant lie son socket à une adresse de socket donnée et attend ensuite de recevoir de nouveaux octets, en utilisant le socket ``sock`` déjà créé.
Depending on the socket address family, the operating system might implicitly assign an address to an unbound socket upon a call to ``write``, ``send`` or ``sendto``. While this is a useful behavior, describing it precisely is out of the scope of this section. En fonction de la famille d'adresse de la socket, le système d'exploitation peut implicitement assigner une adresse à un socket non liée lors d'un appel à ``write``, ``send`` ou ``sendto``. Bien que ce comportement soit utile, sa description précise n'entre pas dans le cadre de cette section.
Using this code, the program will read and print an arbitrary message received from an arbitrary peer who knows the program's socket address. If we want to know the address of the peer that sent us the message, we can use the ``recvfrom`` system call. This is what a modified version of ``bind_and_receive_from_peer`` is doing below. En utilisant ce code, le programme lira et imprimera un message arbitraire reçu d'un homologue arbitraire qui connaît l'adresse de socket du programme. Si nous voulons connaître l'adresse de l'homologue qui nous a envoyé le message, nous pouvons utiliser l'appel système ``recvfrom``. C'est ce que fait une version modifiée de ``bind_and_receive_from_peer`` ci-dessous.
This function is now using the ``recvfrom`` system call that will also provide the address of the peer who sent the message. As addresses are generic and can have different sizes, ``recvfrom`` also tells us the size of the address that it has written. Cette fonction utilise maintenant l'appel système ``recvfrom`` qui fournira également l'adresse du pair qui a envoyé le message. Comme les adresses sont génériques et peuvent avoir différentes tailles, ``recvfrom`` nous indique également la taille de l'adresse qu'il a écrite.
``connect``: connecting a socket to a remote address ``connect``:connecter un socket à une adresse distante
This system call will assign the socket ``sockfd`` to the ``addr`` remote socket address. The process can then use the ``send`` and ``write`` system calls that do not to specify the destination socket address. Furthermore, the calls to ``recv`` and ``read`` will only deliver messages sent by this remote address. This is useful when we only care about the other peer messages. Cet appel système va assigner la socket ``sockfd`` à l'adresse de socket distante ``addr``. Le processus peut alors utiliser les appels système ``send`` et ``write`` qui ne spécifient pas l'adresse de la socket de destination. De plus, les appels à ``recv`` et ``read`` ne délivreront que les messages envoyés par cette adresse distante. Ceci est utile lorsque l'on ne s'intéresse qu'aux messages des autres pairs.
The following program connects a socket to a remote address, sends a message and waits for a reply. Le programme suivant connecte un socket à une adresse distante, envoie un message et attend une réponse.
Creating a new socket to communicate through a network Création d'une nouvelle socket pour communiquer via un réseau
Until now, we learned how to use sockets that were already created. When writing a whole program, you will have to create you own sockets and choose the concrete technology that it will use to communicate with others. In this section, we will create new sockets and allow a program to communicate with processes located on another computer using a network. The most recent standardized technology used to communicate through a network is the :term:`IPv6` network protocol. In the IPv6 protocol, hosts are identified using *IPv6 addresses*. Modern operating systems allow IPv6 network communications between programs to be done using the socket API, just as we did in the previous sections. Jusqu'à présent, nous avons appris à utiliser des sockets déjà créés. Lorsque vous écrirez un programme complet, vous devrez créer vos propres sockets et choisir la technologie concrète qu'il utilisera pour communiquer avec les autres. Dans cette section, nous allons créer de nouveaux sockets et permettre à un programme de communiquer avec des processus situés sur un autre ordinateur en utilisant un réseau. La technologie standardisée la plus récente utilisée pour communiquer via un réseau est le protocole réseau :term:`IPv6`. Dans le protocole IPv6, les hôtes sont identifiés à l'aide d'adresses *IPv6*. Les systèmes d'exploitation modernes permettent d'établir des communications réseau IPv6 entre programmes à l'aide de l'API socket, comme nous l'avons fait dans les sections précédentes.
A program can use the ``socket`` system call to create a new socket. Un programme peut utiliser l'appel système ``socket`` pour créer un nouveau socket.
The ``domain`` parameter specifies the address family that we will use to concretely perform the communication. For an IPv6 socket, the ``domain`` parameter will be set to the value ``AF_INET6``, telling the operating system that we plan to communicate using IPv6 addresses. The ``type`` parameter specifies the communication guarantees that we need. For now, we will use the type ``SOCK_DGRAM`` which allows us to send *unreliable messages*. This means that each data that we send at each call of ``sendto`` will either be completely received or not received at all. The last parameter will be set to ``0``. The following line creates a socket, telling the operating system that we want to communicate using IPv6 addresses and that we want to send unreliable messages. Le paramètre ``domain`` spécifie la famille d'adresses que nous allons utiliser pour réaliser concrètement la communication. Pour une socket IPv6, le paramètre ``domain`` prendra la valeur ``AF_INET6``, indiquant au système d'exploitation que nous prévoyons de communiquer en utilisant des adresses IPv6. Le paramètre ``type`` spécifie les garanties de communication dont nous avons besoin. Pour l'instant, nous allons utiliser le type ``SOCK_DGRAM`` qui nous permet d'envoyer des *messages non fiables*. Cela signifie que chaque donnée que nous envoyons à chaque appel de ``sendto`` sera soit complètement reçue, soit pas du tout reçue. Le dernier paramètre sera fixé à "0". La ligne suivante crée un socket, indiquant au système d'exploitation que nous voulons communiquer en utilisant des adresses IPv6 et que nous voulons envoyer des messages non fiables.
Sending a message to a remote peer using its IPv6 address Envoi d'un message à un homologue distant en utilisant son adresse IPv6
Now that we created an IPv6 socket, we can use it to reach another program if we know its IPv6 address. IPv6 addresses have a human-readable format that can be represented as a string of characters. The details of IPv6 addresses are out of scope of this section but here are some examples : Maintenant que nous avons créé un socket IPv6, nous pouvons l'utiliser pour atteindre un autre programme si nous connaissons son adresse IPv6. Les adresses IPv6 ont un format lisible par l'homme qui peut être représenté par une chaîne de caractères. Les détails des adresses IPv6 sont hors de portée de cette section mais voici quelques exemples :
The ``::1`` IPv6 address identifies the computer on which the current program is running. L'adresse IPv6 ``::1`` identifie l'ordinateur sur lequel le programme tourne.
The ``2001:6a8:308f:9:0:82ff:fe68:e520`` IPv6 address identifies the computer serving the ``https://beta.computer-networking.info`` website. L'adresse IPv6 ``2001:6a8:308f:9:0:82ff:fe68:e520`` identifie l'ordinateur qui dessert le site ``https://beta.computer-networking.info``.
An IPv6 address often identifies a computer and not a program running on the computer. In order to identify a specific program running on a specific computer, we use a *port number* in addition to the IPv6 address. A program using an IPv6 socket is this identified using : Une adresse IPv6 identifie souvent un ordinateur et non pas un programme exécuté sur cet ordinateur. Afin d'identifier un programme spécifique fonctionnant sur un ordinateur spécifique, nous utilisons un *numéro de port* en plus de l'adresse IPv6. Un programme utilisant un socket IPv6 est ainsi identifié par :
The IPv6 address of the computer L'adresse IPv6 de l'ordinateur
The port number identifying the program running on the computer Le port du programme qui tourne sur l'ordinateur
A program can use the ``struct sockaddr_in6`` to represent IPv6 socket addresses. The following program creates a ``struct sockaddr_in6`` that identifies the program that reserved the port number ``55555`` on the computer identified by the ``::1`` IPv6 address. Un programme peut utiliser la structure sockaddr_in6 pour représenter les adresses de socket IPv6. Le programme suivant crée une ``struct sockaddr_in6`` qui identifie le programme ayant réservé le numéro de port ``55555`` sur l'ordinateur identifié par l'adresse IPv6 ``::1``.
Now, we have built everything we need to send a message to the remote program. The ``create_socket_and_send_message`` function below assembles all the building blocks we created until now in order to send the message ``"hello"`` to the program running on port ``55555`` on the computer identified by the ``::1`` IPv6 address. Maintenant, nous avons construit tout ce dont nous avons besoin pour envoyer un message au programme distant. La fonction ``create_socket_and_send_message`` ci-dessous assemble toutes les briques que nous avons créées jusqu'à présent afin d'envoyer le message ``hello"`` au programme tournant sur le port ``55555`` sur l'ordinateur identifié par l'adresse IPv6 ``::1``.
Note that we can reuse our ``send_hello_to_peer`` function without any modification as we wrote it to handle any kind of sockets, including sockets using the IPv6 network protocol. Notez que nous pouvons réutiliser notre fonction ``send_hello_to_peer`` sans aucune modification puisque nous l'avons écrite pour gérer tout type de sockets, y compris les sockets utilisant le protocole réseau IPv6.
Endianness: exchanging integers between different computers Endianness : échange d'entiers entre différents ordinateurs
Besides character strings, some applications also need to exchange 16 bits and 32 bits fields such as integers. A naive solution would have been to send the 16- or 32-bits field as it is encoded in the host's memory. Unfortunately, there are different methods to store 16- or 32-bits fields in memory. Some CPUs store the most significant byte of a 16-bits field in the first address of the field while others store the least significant byte at this location. When networked applications running on different CPUs exchange 16 bits fields, there are two possibilities to transfer them over the transport service : Outre les chaînes de caractères, certaines applications doivent également échanger des champs de 16 et 32 bits tels que des entiers. Une solution naïve aurait été d'envoyer le champ de 16 ou 32 bits tel qu'il est codé dans la mémoire de l'hôte. Malheureusement, il existe différentes méthodes pour stocker les champs de 16 ou 32 bits en mémoire. Certains processeurs stockent l'octet le plus significatif d'un champ de 16 bits dans la première adresse du champ, tandis que d'autres stockent l'octet le moins significatif à cet endroit. Lorsque des applications en réseau fonctionnant sur des unités centrales différentes échangent des champs de 16 bits, il existe deux possibilités pour les transférer via le service de transport :
send the most significant byte followed by the least significant byte envoyer l'octet le plus significatif suivi de l'octet le moins significatif
send the least significant byte followed by the most significant byte envoyer l'octet le moins significatif suivi de l'octet le plus significatif

Loading…

User avatar pdan1

New translation

cnp3-ebook / exercises/socketsFrench

3 years ago
Browse all component changes

Glossary

English French
No related strings found in the glossary.

String information

Source string location
../../exercises/sockets.rst:264
String age
4 years ago
Source string age
4 years ago
Translation file
locale/fr/LC_MESSAGES/exercises/sockets.po, string 28