Академический Документы
Профессиональный Документы
Культура Документы
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
Jargon : « Stream » (flux) Programmation Sockets avec TCP
7
/
(&*
6
-
"
" # %
"#
*
38
(&
/ *
3
.
/
/
(inFromUser
(#
* *
/#
#
#
(outToServer
(&
*
3
.
(
* *
9*
#
38
4*
#
#
38
:
/#
*
(
&&3*
38
&
(inFromServer
*
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
import java.io.*;
import java.net.*;
class ClientTCP {
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
Exemple: client Java (TCP) ... Exemple: serveur Java (TCP)
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
)%
;<
#
!
Créer le flux de sortie
attaché à la socket DataOutputStream sortieVersClient =
/
new DataOutputStream(connectionSocket.getOutputStream());
/
)
Lire la chaîne
phraseClient = entreeDepuisClient.readLine();
depuis la socket
3-
-
phraseMajuscule = phraseClient.toUpperCase() + '\n';
#
Ecrire au client sortieVersClient.writeBytes(phraseMajuscule); /
)
} // fin boucle (repartir et attendre une nouvelle connexion)
/
} -
=
}
)%
1
=
Intéraction
client/serveur UDP
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
Client Java (UDP) Exemple: client Java (UDP)
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
Couche Application : programmation avec les Sockets Couche Application : programmation avec les Sockets
Exemple: serveur Java (UDP) ...
donneeEnvoyee = phraseMajuscule.getBytes();
Créer le datagramme
DatagramPacket paquetEnvoye =
à envoyer au client new DatagramPacket(donneeEnvoyee,
donneeEnvoyee.length, adresseIP,
port);
Ecrire le datagramme
socketServeur.send(paquetEnvoye);
sur la socket
} // fin boucle (repartir en attente d'un autre datagramme)
}
}