Probleme socket
Fermé
Hacker#1
Messages postés
76
Date d'inscription
mardi 6 janvier 2009
Statut
Membre
Dernière intervention
20 avril 2010
-
21 oct. 2009 à 15:29
nabil07 Messages postés 140 Date d'inscription vendredi 14 septembre 2007 Statut Membre Dernière intervention 10 avril 2014 - 21 oct. 2009 à 23:08
nabil07 Messages postés 140 Date d'inscription vendredi 14 septembre 2007 Statut Membre Dernière intervention 10 avril 2014 - 21 oct. 2009 à 23:08
A voir également:
- Probleme socket
- Soulseek socket error - Forum Logiciels
- Error 2002 (hy000): can't connect to local server through socket '/run/mysqld/mysqld.sock' (2) - Forum Bases de données
- Socket 1150 vs 1151 - Forum Processeur
- Check_nrpe state critical: socket timeout after 10 seconds. ✓ - Forum Ubuntu
- Socket closed - Forum Java
2 réponses
Hacker#1
Messages postés
76
Date d'inscription
mardi 6 janvier 2009
Statut
Membre
Dernière intervention
20 avril 2010
21 oct. 2009 à 20:44
21 oct. 2009 à 20:44
pas de proposition
nabil07
Messages postés
140
Date d'inscription
vendredi 14 septembre 2007
Statut
Membre
Dernière intervention
10 avril 2014
64
21 oct. 2009 à 23:08
21 oct. 2009 à 23:08
Bonsoir,
ton problème réside dans l'utilisation du flux d'entrée InputStream, car ce dernier ne possède pas une méthode pour lire toute une ligne.
voici une proposition de code :
Code client
Code serveur :
bonne soirée.
ton problème réside dans l'utilisation du flux d'entrée InputStream, car ce dernier ne possède pas une méthode pour lire toute une ligne.
voici une proposition de code :
Code client
import java.io.*; import java.net.*; public class client { public static void main(String args[]) throws IOException{ Socket s=new Socket("localhost",20000); PrintStream out= new PrintStream(s.getOutputStream()); InputStream in=s.getInputStream(); String str="Salut"; int len=str.length(); System.out.println(str+" "+len); out.println(str+""+len); //str=in.readLine(); s.close(); } }
Code serveur :
import java.io.*; import java.net.*; public class server { public static void main(String args[]) throws IOException{ ServerSocket s=new ServerSocket(20000); System.out.println("serveur en ecoute sur le port "+s.getLocalPort()); Socket conn= s.accept(); System.out.println("connexion reçue depuis"+conn.getRemoteSocketAddress()); PrintStream out = new PrintStream(conn.getOutputStream()); InputStream in=conn.getInputStream(); //while(true){ int c; String str = ""; while((c=in.read()) != -1) { str += (char)c; } System.out.println(str); conn.close(); System.out.println("fin du flux de donnees"); //} } }
bonne soirée.