Client serveur

523 mots 3 pages
Exemple de programmes :(Echange de message entre un client et un serveur)
Serveur2.java : import java.io.IOException; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class Serveur2 { public static void main(String[] zero) {
ServerSocket s ;
Socket so ;
PrintWriter out; try { s = new ServerSocket(2009);
System.out.println("Le serveur est à l'écoute du port "+s.getLocalPort()); so = s.accept();
System.out.println("Un Client s'est connecté"); out = new PrintWriter(so.getOutputStream()); out.println("Vous êtes connecté Client !"); out.flush(); so.close();
s.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Client2.java : import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; public class Client2 { public static void main(String[] zero) {
Socket s1;
BufferedReader in; try { s1 = new Socket(InetAddress.getLocalHost(),2009);
System.out.println("Demande de connexion"); in = new BufferedReader (new InputStreamReader (s1.getInputStream()));
System.out.println(in.readLine());
s1.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}

Exemple de programmes :(Etablir une communication entre un client et un serveur)
Serveur.java :
Import java.io.IOException;
Import java.net.ServerSocket;
Import java.net.Socket; public class Serveur { public static void main(String[ ] zero) {
ServerSocket s ;
Socket soc ; try { s = new ServerSocket(2009); soc = s.accept();
System.out.println("Un Client s'est connecté !"); soc.close(); s.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Client.java
import java.io.IOException; import java.net.InetAddress; import java.net.Socket;
import

en relation

  • Travail de fin d'etude chatbot
    12265 mots | 50 pages
  • client mistère
    3800 mots | 16 pages
  • Openerp connecteur jasper
    1062 mots | 5 pages
  • jdbc java
    5371 mots | 22 pages
  • Fiche cliente
    268 mots | 2 pages
  • Fiche Clients
    612 mots | 3 pages
  • Cadre
    422 mots | 2 pages
  • FICHE FDSA
    604 mots | 3 pages
  • Comportement des clients
    487 mots | 2 pages
  • Client mystere
    7809 mots | 32 pages
  • Dossier client
    31322 mots | 126 pages
  • Clientys
    1242 mots | 5 pages
  • Fiche client
    267 mots | 2 pages
  • Service client
    1241 mots | 5 pages
  • Gestion automatisée d'école
    1849 mots | 8 pages