Programation des socket
Résolu
taznakhte
Messages postés
63
Date d'inscription
Statut
Membre
Dernière intervention
-
taznakhte Messages postés 63 Date d'inscription Statut Membre Dernière intervention -
taznakhte Messages postés 63 Date d'inscription Statut Membre Dernière intervention -
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
- Error 2002 (hy000): can't connect to local server through socket '/run/mysqld/mysqld.sock' (2) ✓ - Forum Linux / Unix
- Programation - Forum Programmation
- Carte mere socket 1155 ✓ - Forum Carte-mère/mémoire
- Logiciel de programation - Forum Programmation