1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
public class Serveur
{ public static void main (String args[]) throws IOException
{ int port = 1000 ;
String hote = "127.0.0.1" ;
InetAddress LocaleAdresse ;
LocaleAdresse = InetAddress.getLocalHost();
int nb=1000;
ServerSocket sersoc = new ServerSocket (port,nb,LocaleAdresse) ;
System.out.println ("serveur active sur port " + port) ;
Socket soc = sersoc.accept();
InputStream flux= soc.getInputStream ();
flux = soc.getInputStream ();
while (true)
{
BufferedReader entree = new BufferedReader (new InputStreamReader (flux)) ;
String message = entree.readLine();
{
System.out.println("je suis sortie");
}
System.out.println("message reçu sur le serveur = " + message) ;
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package client;
/**
*
* @author adel
*/
import java.net.* ;
import java.io.* ;
public class Client
{ public static void main (String args[]) throws IOException
{ InetAddress LocaleAdresse ;
LocaleAdresse = InetAddress.getLocalHost();
int port = 1000 ;
Socket soc = new Socket (LocaleAdresse , port) ;
OutputStream flux = soc.getOutputStream() ;
PrintWriter out = new PrintWriter(flux);
out.println("fffffffffffff");
out.println("test");
out.println("end");
out.close();
// pour forcer l'envoi de la ligne
}
} |
Partager