Je cherche à émettre des données (une chaîne de 30 caractères) en
broadcast UDP. Si je sais me débrouiller pour les socket TCP (et encore
je n'ai pas tenté le broadcast), pour les sockets UDP j'ai du mal à voir
comment configurer la socket afin de pouvoir écrire à partir d'une
machine et lire à partir de plusieurs autres.
Jusque-là, pour mes serveurs, je faisais la recette habituelle :
- pour les serveurs :
socket()
setsockopt() pour REUSEADDR et LINGER
bind()
listen()
- pour les clients :
socket()
setsockopt() (idem)
bind()
connect()
Or pour les sockets UDP en broadcast, je ne vois pas trop comment
faire. Pour l'instant (ce qui ne marche pas) :
socket()
setsockopt() pour REUSEADDR et BROADCAST
connect()
Puis write() ou send() pour écrire et read() ou recv() pour lire.
Quelqu'un a-t-il une idée sur la méthode à appliquer ?
Merci d'avance.
If from is non-nil, and the socket is not connection-oriented, the source address of the message is filled in. Fromlen is a value-result parame- ter, initialized to the size of the buffer associated with from, and mod- ified on return to indicate the actual size of the address stored there.
en résumé, fromlen doit avoir une valeur initiale intéressante.
-- DINH V. Hoa,
"écrire 'dsl' au lieu de 'désolé', c'est pas un problème d'orthographe, c'est un problème de capillarité palmaire" -- ed
recvfrom() étant bloquant, le programme s'arrête sur lui et rien n'est
reçu. Pourtant tcpdump me montre tout...
If from is non-nil, and the socket is not connection-oriented, the source
address of the message is filled in. Fromlen is a value-result parame-
ter, initialized to the size of the buffer associated with from, and mod-
ified on return to indicate the actual size of the address stored there.
en résumé, fromlen doit avoir une valeur initiale intéressante.
--
DINH V. Hoa,
"écrire 'dsl' au lieu de 'désolé', c'est pas un problème d'orthographe,
c'est un problème de capillarité palmaire" -- ed
If from is non-nil, and the socket is not connection-oriented, the source address of the message is filled in. Fromlen is a value-result parame- ter, initialized to the size of the buffer associated with from, and mod- ified on return to indicate the actual size of the address stored there.
en résumé, fromlen doit avoir une valeur initiale intéressante.
-- DINH V. Hoa,
"écrire 'dsl' au lieu de 'désolé', c'est pas un problème d'orthographe, c'est un problème de capillarité palmaire" -- ed
Thomas Nemeth
DINH Viêt Hoà a tapoté :
recvfrom() étant bloquant, le programme s'arrête sur lui et rien n'est reçu. Pourtant tcpdump me montre tout...