Programation des socket
Résolu
taznakhte
Messages postés
85
Statut
Membre
-
taznakhte Messages postés 85 Statut Membre -
taznakhte Messages postés 85 Statut Membre -
Bonjour,
azul
j'ai un problème lors de l'exécution des programmes (en java), des socket entre le clavier et le moniteur,suivant :
du client (clavier):
import java.io.*;
import java.net.*;
class clientTCP{
public static void main(String argv[]) throws Exception
{
String phrase;
String phraseModifiee;
BufferedReader entreeDepuisUtilisateur = new BufferedReader(new InputStreamReader(System.in));
Socket socketClient = new Socket("localhost", 4567);
PrintWriter sortieVersServeur = new PrintWriter(socketClient.getOutputStream(),true);
BufferedReader entreeDepuisServeur = new BufferedReader(new InputStreamReader(socketClient.getInputStream()));
phrase = entreeDepuisUtilisateur.readLine();
sortieVersServeur.println(phrase);
phraseModifiee = entreeDepuisServeur.readLine();
System.out.println("RECU DU SERVEUR: " + phraseModifiee);
entreeDepuisUtilisateur.close();
entreeDepuisServeur.close();
sortieVersServeur.close();
socketClient.close();
}
}
et pour le serveur (monoteur):
import java.io.*;
import java.net.*;
class serveurTCP {
public static void main(String argv[]) throws Exception
{
String phraseClient;
String phraseMajuscule;
ServerSocket socketEcoute = new ServerSocket(4567);
while(true) { // boucle infinie
Socket socketConnexion = socketEcoute.accept();
BufferedReader entreeDepuisClient =
new BufferedReader(new
InputStreamReader(socketConnexion.getInputStream()));
PrintWriter sortieVersClient =
new PrintWriter(socketConnexion.getOutputStream(),true);
phraseClient = entreeDepuisClient.readLine();
phraseMajuscule = phraseClient.toUpperCase();
sortieVersClient.println(phraseMajuscule);
} // fin boucle (repartir et attendre une nouvelle connexion)
}
}
on utilisant le protocole TCP
merci (tanmmirte)!!!!!!!!!!!
azul
j'ai un problème lors de l'exécution des programmes (en java), des socket entre le clavier et le moniteur,suivant :
du client (clavier):
import java.io.*;
import java.net.*;
class clientTCP{
public static void main(String argv[]) throws Exception
{
String phrase;
String phraseModifiee;
BufferedReader entreeDepuisUtilisateur = new BufferedReader(new InputStreamReader(System.in));
Socket socketClient = new Socket("localhost", 4567);
PrintWriter sortieVersServeur = new PrintWriter(socketClient.getOutputStream(),true);
BufferedReader entreeDepuisServeur = new BufferedReader(new InputStreamReader(socketClient.getInputStream()));
phrase = entreeDepuisUtilisateur.readLine();
sortieVersServeur.println(phrase);
phraseModifiee = entreeDepuisServeur.readLine();
System.out.println("RECU DU SERVEUR: " + phraseModifiee);
entreeDepuisUtilisateur.close();
entreeDepuisServeur.close();
sortieVersServeur.close();
socketClient.close();
}
}
et pour le serveur (monoteur):
import java.io.*;
import java.net.*;
class serveurTCP {
public static void main(String argv[]) throws Exception
{
String phraseClient;
String phraseMajuscule;
ServerSocket socketEcoute = new ServerSocket(4567);
while(true) { // boucle infinie
Socket socketConnexion = socketEcoute.accept();
BufferedReader entreeDepuisClient =
new BufferedReader(new
InputStreamReader(socketConnexion.getInputStream()));
PrintWriter sortieVersClient =
new PrintWriter(socketConnexion.getOutputStream(),true);
phraseClient = entreeDepuisClient.readLine();
phraseMajuscule = phraseClient.toUpperCase();
sortieVersClient.println(phraseMajuscule);
} // fin boucle (repartir et attendre une nouvelle connexion)
}
}
on utilisant le protocole TCP
merci (tanmmirte)!!!!!!!!!!!
A voir également:
- Programation des socket
- Programation ✓ - Forum Programmation
- Programation - Forum Programmation
- Etudier la programation - Forum Programmation
- Socket processeur - Forum Processeur
- Programation - Forum Programmation