Exemple48_SocketSecurityRetourTélécharger Client.java import java.awt.*; import java.io.*; import java.net.*; public class Client { static public void main(String args[]) throws Exception { System.setSecurityManager(new SecurityManager()); System.out.println("Addr: "+Inet4Address.getLocalHost()); Socket soc = new Socket(Inet4Address.getByName(args[0]),9100, Inet4Address.getLocalHost(),9101); OutputStream os=soc.getOutputStream(); DataOutputStream dos=new DataOutputStream(os); while(true) { DataInputStream in = new DataInputStream(System.in); System.out.print("> "); System.out.flush(); String valeur= in.readLine(); dos.writeUTF(valeur); } } } Serveur.java import java.io.*; import java.awt.*; import java.net.*; public class Serveur { public static void main(String args[]) throws Exception { System.setSecurityManager(new SecurityManager()); String str; ServerSocket ssoc; ssoc = new ServerSocket(9100); while(true) { System.out.println("En attente..."); Socket soc = ssoc.accept(); System.out.println("Socket accepte " + soc.getPort()+ " "+soc.getLocalPort()); InputStream is = soc.getInputStream(); DataInputStream dis = new DataInputStream(is); System.out.println("Lecture du socket"); str = dis.readUTF(); System.out.println("RECU: "+str); } } } compil.bat mkdir bin del /f /s /q bin\*.class javac -d bin *.java pause java.policy grant{ permission java.net.SocketPermission "*:9100-9110","accept,connect,listen"; }; java.policy.AllPermissions grant{ permission java.security.AllPermission; }; runClient.bat java -Djava.security.policy=java.policy -classpath bin Client 192.168.0.46 pause runServeur.bat java -Djava.security.policy=java.policy -classpath "bin" Serveur pause