essmoez22
Messages postés1Date d'inscriptionmardi 2 février 2010StatutMembreDernière intervention15 octobre 2010 15 oct. 2010 à 13:28
mllmml
kamal_tayri
Messages postés7Date d'inscriptiondimanche 16 avril 2006StatutMembreDernière intervention 1 mai 2006 1 mai 2006 à 16:41
salut,
l'excellente application que vous avez publié au site(javafr.com)a attiré mon attention,car je suis entrain de réaliser une petite application qui semble mais simple par rapport à la votre.c'est pour cela j'ai besoin de votre aide,et voila une description de mon modeste travai:
j'ai fait 3 codes en java bien executés(se sont les pieces jointes avec ce message)un code pour le serveur,le 2 pour le client,et le 3 pour cryptage et decryptage de texte(avec l'algorithme DES).j'execute le code de serveur tout d'abord et ensuite le code du client sans fermer l'execution de code de serveur et comme ça je peux etablir une communication client/serveur.
mon probleme est de faire 2 interfaces:
*une pour le client:elle contient une zone de texte pour saisir un message,un bouton<crypter>pour crypter le message saisi dans la zone de texte"en exploitant le code de cryptage et decryptage",et un bouton<envoyer>pour envoyer au serveur le message crypté de la zone de texte.
*l'autre interface est pour le serveur:elle contient une zone de texte pour afficher le message crypté envoyé par le client,et un bouton<decrypter>pour decrypter le message crypté affiché dans la zone de texte de l'interface(serveur)"en exploitant encore une fois le code de cryptage et decryptage"
En attendant une réponse favorable,je vous prie d'agréer,Monsieur,l'expression de mon profond respect.
voila les 3 codes:
/////////////code pour le serveur///////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class serverChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port to the PDA client
// Sockets
ServerSocket serverSocket = null; // ServerSocket
//listening to the Client
Socket clientSocket = null; // Socket with Client
// Strings
String msg_String = null;
int msg_hash = 0;
int i = 0;
int Clientconnected = 0; // Connection marker
/********End declarations*********/
/****************Server Socket Creation**********/
System.out.print("\nCreation of the ServerSocket\nlistening to port 3000 \nfor client.");
try {
System.out.print(".");
serverSocket = new ServerSocket(port);
//Socket // listening on port 3000
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("...failed.\nProblem in the creation of the ServerSocket: " +e);
System.exit(1);
}
try {
clientSocket = serverSocket.accept();
Clientconnected = 1;
}
catch (IOException e) {
System.out.println("Unable to deal with BufferedReader and PrintWriter for the clientSocket : " +e);
System.exit(1);
}
/***************End of creation of Sockets*******/
try {
isClient = new BufferedReader(new InputStreamReader(clientSocket.
getInputStream()));
osClient = new PrintWriter (clientSocket.getOutputStream());
}
catch (IOException e) {
System.out.println("Cant't deal with the streams : " + e);
}
while (true) {
try {
msg_String = isClient.readLine();
System.out.println("String from the client : " + msg_String);
}
catch (IOException e) {
System.out.println("Couldn't get I/O for the connection to: ");
System.exit(1);
}
if (msg_String.trim().equals("/bye")) {
Clientconnected = 0;
clientSocket.close();
serverSocket.close();
System.exit(0);
}
if (Clientconnected == 1) {
try {
System.out.print("\nComputing...");
msg_hash = msg_String.hashCode();
System.out.print("done");
osClient.println(msg_hash);
osClient.flush(); // put it onto the network
System.out.print("...and sent.\n");
} //try
catch (Exception e) {
System.out.println(e);
System.exit(1);
} // catch
} // if Clientconnected
} // while
// System.exit(0);
} // void main
} // PDAServer class
////////////code pour client//////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class clientChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port
String myHost = "localhost";
// Strings
String myString = null;
String sString = null;
int i = 0; // Translation counter
int Clientconnected = 0; // Connection marker
/********End declarations*********/
try {
System.out.print("\nClient.");
clientSocket = new Socket(myHost, port);
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("..failed.\nProblem in the creation of the Socket : " + e);
System.exit(1);
} //catch
try {
osClient = new PrintWriter(clientSocket.getOutputStream());
isClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
readfromline = new BufferedReader(new InputStreamReader(System.in));
}
catch (IOException e) {
System.out.println("Can't deal with the streams... : " + e);
} //catch
try {
while (true) {
myString = readfromline.readLine();
if (myString.trim().equals("/bye")) {
osClient.println("/bye");
osClient.flush();
clientSocket.close();
System.exit(1);
}
osClient.println(myString); // Write it
osClient.flush(); // put it onto the network
System.out.println("\nSending...: '" + myString + "' ...done.");
myString = isClient.readLine();
System.out.println("From server :-[===> " + myString + "\n");
} //while
} //try
catch (Exception e) {
System.out.println("Exception while sending data" + e);
System.exit(1);
} // catch
System.out.println("Closing connection to client");
// System.exit(0);
} // void main
} // clientChat class
////////////code pour cryptage et decryptage/////////
import java.security.*;
import javax.crypto.*;
// encrypt and decrypt using the DES private key algor
public class PrivateExemple {
public static void main(String[] args) throws Exception {
// check args and get plaintext
//byte[] plainText = args[0].getBytes("UTF8");
String ss = "je suis un marocain";
byte[] plainText = ss.getBytes();
// get a DES private key
System.out.println("\nStart generating DES key");
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
keyGen.init(56);
Key key = keyGen.generateKey();
System.out.println("Finish generating DES key");
// get a DES cipher object and print the provide
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
System.out.println("\n" + cipher.getProvider().getInfo());
// encrypt using the key and the plaintext
System.out.println("\nStart encryption");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText = cipher.doFinal(plainText);
System.out.println("Finish encryption: ");
System.out.println(new String(cipherText, "UTF8"));
// decrypt the ciphertext using the same key
System.out.println("\nStart decryption");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] newPlainText = cipher.doFinal(cipherText);
System.out.println("Finish decryption: ");
System.out.println(new String(newPlainText, "UTF8"));
}
}
mon msn est:kamal_tayri@hotmail.com
et merci beaucoup
kamal_tayri
Messages postés7Date d'inscriptiondimanche 16 avril 2006StatutMembreDernière intervention 1 mai 2006 1 mai 2006 à 16:40
salut,
l'excellente application que vous avez publié au site(javafr.com)a attiré mon attention,car je suis entrain de réaliser une petite application qui semble mais simple par rapport à la votre.c'est pour cela j'ai besoin de votre aide,et voila une description de mon modeste travai:
j'ai fait 3 codes en java bien executés(se sont les pieces jointes avec ce message)un code pour le serveur,le 2 pour le client,et le 3 pour cryptage et decryptage de texte(avec l'algorithme DES).j'execute le code de serveur tout d'abord et ensuite le code du client sans fermer l'execution de code de serveur et comme ça je peux etablir une communication client/serveur.
mon probleme est de faire 2 interfaces:
*une pour le client:elle contient une zone de texte pour saisir un message,un bouton<crypter>pour crypter le message saisi dans la zone de texte"en exploitant le code de cryptage et decryptage",et un bouton<envoyer>pour envoyer au serveur le message crypté de la zone de texte.
*l'autre interface est pour le serveur:elle contient une zone de texte pour afficher le message crypté envoyé par le client,et un bouton<decrypter>pour decrypter le message crypté affiché dans la zone de texte de l'interface(serveur)"en exploitant encore une fois le code de cryptage et decryptage"
En attendant une réponse favorable,je vous prie d'agréer,Monsieur,l'expression de mon profond respect.
voila les 3 codes:
/////////////code pour le serveur///////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class serverChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port to the PDA client
// Sockets
ServerSocket serverSocket = null; // ServerSocket
//listening to the Client
Socket clientSocket = null; // Socket with Client
// Strings
String msg_String = null;
int msg_hash = 0;
int i = 0;
int Clientconnected = 0; // Connection marker
/********End declarations*********/
/****************Server Socket Creation**********/
System.out.print("\nCreation of the ServerSocket\nlistening to port 3000 \nfor client.");
try {
System.out.print(".");
serverSocket = new ServerSocket(port);
//Socket // listening on port 3000
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("...failed.\nProblem in the creation of the ServerSocket: " +e);
System.exit(1);
}
try {
clientSocket = serverSocket.accept();
Clientconnected = 1;
}
catch (IOException e) {
System.out.println("Unable to deal with BufferedReader and PrintWriter for the clientSocket : " +e);
System.exit(1);
}
/***************End of creation of Sockets*******/
try {
isClient = new BufferedReader(new InputStreamReader(clientSocket.
getInputStream()));
osClient = new PrintWriter (clientSocket.getOutputStream());
}
catch (IOException e) {
System.out.println("Cant't deal with the streams : " + e);
}
while (true) {
try {
msg_String = isClient.readLine();
System.out.println("String from the client : " + msg_String);
}
catch (IOException e) {
System.out.println("Couldn't get I/O for the connection to: ");
System.exit(1);
}
if (msg_String.trim().equals("/bye")) {
Clientconnected = 0;
clientSocket.close();
serverSocket.close();
System.exit(0);
}
if (Clientconnected == 1) {
try {
System.out.print("\nComputing...");
msg_hash = msg_String.hashCode();
System.out.print("done");
osClient.println(msg_hash);
osClient.flush(); // put it onto the network
System.out.print("...and sent.\n");
} //try
catch (Exception e) {
System.out.println(e);
System.exit(1);
} // catch
} // if Clientconnected
} // while
// System.exit(0);
} // void main
} // PDAServer class
////////////code pour client//////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class clientChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port
String myHost = "localhost";
// Strings
String myString = null;
String sString = null;
int i = 0; // Translation counter
int Clientconnected = 0; // Connection marker
/********End declarations*********/
try {
System.out.print("\nClient.");
clientSocket = new Socket(myHost, port);
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("..failed.\nProblem in the creation of the Socket : " + e);
System.exit(1);
} //catch
try {
osClient = new PrintWriter(clientSocket.getOutputStream());
isClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
readfromline = new BufferedReader(new InputStreamReader(System.in));
}
catch (IOException e) {
System.out.println("Can't deal with the streams... : " + e);
} //catch
try {
while (true) {
myString = readfromline.readLine();
if (myString.trim().equals("/bye")) {
osClient.println("/bye");
osClient.flush();
clientSocket.close();
System.exit(1);
}
osClient.println(myString); // Write it
osClient.flush(); // put it onto the network
System.out.println("\nSending...: '" + myString + "' ...done.");
myString = isClient.readLine();
System.out.println("From server :-[===> " + myString + "\n");
} //while
} //try
catch (Exception e) {
System.out.println("Exception while sending data" + e);
System.exit(1);
} // catch
System.out.println("Closing connection to client");
// System.exit(0);
} // void main
} // clientChat class
////////////code pour cryptage et decryptage/////////
import java.security.*;
import javax.crypto.*;
// encrypt and decrypt using the DES private key algor
public class PrivateExemple {
public static void main(String[] args) throws Exception {
// check args and get plaintext
//byte[] plainText = args[0].getBytes("UTF8");
String ss = "je suis un marocain";
byte[] plainText = ss.getBytes();
// get a DES private key
System.out.println("\nStart generating DES key");
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
keyGen.init(56);
Key key = keyGen.generateKey();
System.out.println("Finish generating DES key");
// get a DES cipher object and print the provide
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
System.out.println("\n" + cipher.getProvider().getInfo());
// encrypt using the key and the plaintext
System.out.println("\nStart encryption");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText = cipher.doFinal(plainText);
System.out.println("Finish encryption: ");
System.out.println(new String(cipherText, "UTF8"));
// decrypt the ciphertext using the same key
System.out.println("\nStart decryption");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] newPlainText = cipher.doFinal(cipherText);
System.out.println("Finish decryption: ");
System.out.println(new String(newPlainText, "UTF8"));
}
}
mon msn est:kamal_tayri@hotmail.com
et merci beaucoup
root2004
Messages postés6Date d'inscriptionmercredi 27 octobre 2004StatutMembreDernière intervention 9 mai 2011 27 avril 2006 à 05:47
Essayez d'utiliser votre ip internet et non pas votre ip réseau pour voir s'il marche ;).
GillesWebmaster
Messages postés496Date d'inscriptionmercredi 30 juin 2004StatutMembreDernière intervention29 juillet 20091 5 mars 2006 à 17:57
Je me demande quelle est votre version de java?
mobilicorpus
Messages postés18Date d'inscriptionmardi 3 mai 2005StatutMembreDernière intervention 5 mars 2006 5 mars 2006 à 17:22
quel est exactement le problème ?
Qu'est ce qu'il ne marche pas ?
GillesWebmaster
Messages postés496Date d'inscriptionmercredi 30 juin 2004StatutMembreDernière intervention29 juillet 20091 5 mars 2006 à 15:46
alors c'est votre version de Java
obydissonn
Messages postés2Date d'inscriptionmardi 19 juillet 2005StatutMembreDernière intervention28 février 2006 28 févr. 2006 à 17:25
jè executé serveur.jar
et client.jar
mais rien ne se passe .
ça marche pa chez moi
mobilicorpus
Messages postés18Date d'inscriptionmardi 3 mai 2005StatutMembreDernière intervention 5 mars 2006 5 févr. 2006 à 10:17
là, je ne vois pas.
le java est-il activé ?
Ce que tu décris MUAD-DIB, c'est la même chose que si on a pas executer le fichier serveur/serveur.jar
Bonne chance
GillesWebmaster
Messages postés496Date d'inscriptionmercredi 30 juin 2004StatutMembreDernière intervention29 juillet 20091 5 févr. 2006 à 08:55
Négatif chez moi tout fonctione mais est-tu sûr d'avoir exécuté le fichier "serveur.jar"???
Je pense faire une révision au mois de mars...
D'ici là,
Bon dimanche à tous
GillesWebmaster
cs_muad-dib
Messages postés103Date d'inscriptionlundi 9 avril 2001StatutMembreDernière intervention16 juillet 2008 4 févr. 2006 à 23:16
yes mais rien ne se passe ... adresse bien 127.0.0.1 .. il ne s'affiche rien dans les liste et quand j envoie un message il ne se passe strictement rien
mobilicorpus
Messages postés18Date d'inscriptionmardi 3 mai 2005StatutMembreDernière intervention 5 mars 2006 4 févr. 2006 à 23:08
muad-dib :
Avez-vous pensez à executer le serveur ?
cs_muad-dib
Messages postés103Date d'inscriptionlundi 9 avril 2001StatutMembreDernière intervention16 juillet 2008 4 févr. 2006 à 22:59
marche po chez moi
GillesWebmaster
Messages postés496Date d'inscriptionmercredi 30 juin 2004StatutMembreDernière intervention29 juillet 20091 8 janv. 2006 à 20:49
oki merci pour ta note...
Mais il est vrai qu'une amélioration s'imposera..
Bonne prog !
GillesWebmaster
mobilicorpus
Messages postés18Date d'inscriptionmardi 3 mai 2005StatutMembreDernière intervention 5 mars 2006 8 janv. 2006 à 20:45
... enfin bon, je trouve que le code est pas mal et pratique pour les réseaux.
La présentation est un petit detail par rapport au code
Je trouve que c'est pas mal pour une première source (j'en ai pas publié encore !)
bonne prog !
GillesWebmaster
Messages postés496Date d'inscriptionmercredi 30 juin 2004StatutMembreDernière intervention29 juillet 20091 8 janv. 2006 à 20:15
Oui je suis d'accord avec toi mais c'était ma première source...
Bonne journée
mobilicorpus
Messages postés18Date d'inscriptionmardi 3 mai 2005StatutMembreDernière intervention 5 mars 2006 8 janv. 2006 à 03:02
pas mal ton script, mais tu peux encore améliorer la présentation, je pense
15 oct. 2010 à 13:28
1 mai 2006 à 16:41
l'excellente application que vous avez publié au site(javafr.com)a attiré mon attention,car je suis entrain de réaliser une petite application qui semble mais simple par rapport à la votre.c'est pour cela j'ai besoin de votre aide,et voila une description de mon modeste travai:
j'ai fait 3 codes en java bien executés(se sont les pieces jointes avec ce message)un code pour le serveur,le 2 pour le client,et le 3 pour cryptage et decryptage de texte(avec l'algorithme DES).j'execute le code de serveur tout d'abord et ensuite le code du client sans fermer l'execution de code de serveur et comme ça je peux etablir une communication client/serveur.
mon probleme est de faire 2 interfaces:
*une pour le client:elle contient une zone de texte pour saisir un message,un bouton<crypter>pour crypter le message saisi dans la zone de texte"en exploitant le code de cryptage et decryptage",et un bouton<envoyer>pour envoyer au serveur le message crypté de la zone de texte.
*l'autre interface est pour le serveur:elle contient une zone de texte pour afficher le message crypté envoyé par le client,et un bouton<decrypter>pour decrypter le message crypté affiché dans la zone de texte de l'interface(serveur)"en exploitant encore une fois le code de cryptage et decryptage"
En attendant une réponse favorable,je vous prie d'agréer,Monsieur,l'expression de mon profond respect.
voila les 3 codes:
/////////////code pour le serveur///////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class serverChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port to the PDA client
// Sockets
ServerSocket serverSocket = null; // ServerSocket
//listening to the Client
Socket clientSocket = null; // Socket with Client
// Inout/Output for PDA Client
BufferedReader isClient = null;
PrintWriter osClient = null;
// Strings
String msg_String = null;
int msg_hash = 0;
int i = 0;
int Clientconnected = 0; // Connection marker
/********End declarations*********/
/****************Server Socket Creation**********/
System.out.print("\nCreation of the ServerSocket\nlistening to port 3000 \nfor client.");
try {
System.out.print(".");
serverSocket = new ServerSocket(port);
//Socket // listening on port 3000
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("...failed.\nProblem in the creation of the ServerSocket: " +e);
System.exit(1);
}
try {
clientSocket = serverSocket.accept();
Clientconnected = 1;
}
catch (IOException e) {
System.out.println("Unable to deal with BufferedReader and PrintWriter for the clientSocket : " +e);
System.exit(1);
}
/***************End of creation of Sockets*******/
try {
isClient = new BufferedReader(new InputStreamReader(clientSocket.
getInputStream()));
osClient = new PrintWriter (clientSocket.getOutputStream());
}
catch (IOException e) {
System.out.println("Cant't deal with the streams : " + e);
}
while (true) {
try {
msg_String = isClient.readLine();
System.out.println("String from the client : " + msg_String);
}
catch (IOException e) {
System.out.println("Couldn't get I/O for the connection to: ");
System.exit(1);
}
if (msg_String.trim().equals("/bye")) {
Clientconnected = 0;
clientSocket.close();
serverSocket.close();
System.exit(0);
}
if (Clientconnected == 1) {
try {
System.out.print("\nComputing...");
msg_hash = msg_String.hashCode();
System.out.print("done");
osClient.println(msg_hash);
osClient.flush(); // put it onto the network
System.out.print("...and sent.\n");
} //try
catch (Exception e) {
System.out.println(e);
System.exit(1);
} // catch
} // if Clientconnected
} // while
// System.exit(0);
} // void main
} // PDAServer class
////////////code pour client//////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class clientChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port
String myHost = "localhost";
// Sockets
Socket clientSocket = null;
// Inout/Output for PDA Client
BufferedReader isClient = null;
PrintWriter osClient = null;
BufferedReader readfromline = null;
// Strings
String myString = null;
String sString = null;
int i = 0; // Translation counter
int Clientconnected = 0; // Connection marker
/********End declarations*********/
try {
System.out.print("\nClient.");
clientSocket = new Socket(myHost, port);
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("..failed.\nProblem in the creation of the Socket : " + e);
System.exit(1);
} //catch
try {
osClient = new PrintWriter(clientSocket.getOutputStream());
isClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
readfromline = new BufferedReader(new InputStreamReader(System.in));
}
catch (IOException e) {
System.out.println("Can't deal with the streams... : " + e);
} //catch
try {
while (true) {
myString = readfromline.readLine();
if (myString.trim().equals("/bye")) {
osClient.println("/bye");
osClient.flush();
clientSocket.close();
System.exit(1);
}
osClient.println(myString); // Write it
osClient.flush(); // put it onto the network
System.out.println("\nSending...: '" + myString + "' ...done.");
myString = isClient.readLine();
System.out.println("From server :-[===> " + myString + "\n");
} //while
} //try
catch (Exception e) {
System.out.println("Exception while sending data" + e);
System.exit(1);
} // catch
System.out.println("Closing connection to client");
// System.exit(0);
} // void main
} // clientChat class
////////////code pour cryptage et decryptage/////////
import java.security.*;
import javax.crypto.*;
// encrypt and decrypt using the DES private key algor
public class PrivateExemple {
public static void main(String[] args) throws Exception {
// check args and get plaintext
//byte[] plainText = args[0].getBytes("UTF8");
String ss = "je suis un marocain";
byte[] plainText = ss.getBytes();
// get a DES private key
System.out.println("\nStart generating DES key");
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
keyGen.init(56);
Key key = keyGen.generateKey();
System.out.println("Finish generating DES key");
// get a DES cipher object and print the provide
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
System.out.println("\n" + cipher.getProvider().getInfo());
// encrypt using the key and the plaintext
System.out.println("\nStart encryption");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText = cipher.doFinal(plainText);
System.out.println("Finish encryption: ");
System.out.println(new String(cipherText, "UTF8"));
// decrypt the ciphertext using the same key
System.out.println("\nStart decryption");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] newPlainText = cipher.doFinal(cipherText);
System.out.println("Finish decryption: ");
System.out.println(new String(newPlainText, "UTF8"));
}
}
mon msn est:kamal_tayri@hotmail.com
et merci beaucoup
1 mai 2006 à 16:40
l'excellente application que vous avez publié au site(javafr.com)a attiré mon attention,car je suis entrain de réaliser une petite application qui semble mais simple par rapport à la votre.c'est pour cela j'ai besoin de votre aide,et voila une description de mon modeste travai:
j'ai fait 3 codes en java bien executés(se sont les pieces jointes avec ce message)un code pour le serveur,le 2 pour le client,et le 3 pour cryptage et decryptage de texte(avec l'algorithme DES).j'execute le code de serveur tout d'abord et ensuite le code du client sans fermer l'execution de code de serveur et comme ça je peux etablir une communication client/serveur.
mon probleme est de faire 2 interfaces:
*une pour le client:elle contient une zone de texte pour saisir un message,un bouton<crypter>pour crypter le message saisi dans la zone de texte"en exploitant le code de cryptage et decryptage",et un bouton<envoyer>pour envoyer au serveur le message crypté de la zone de texte.
*l'autre interface est pour le serveur:elle contient une zone de texte pour afficher le message crypté envoyé par le client,et un bouton<decrypter>pour decrypter le message crypté affiché dans la zone de texte de l'interface(serveur)"en exploitant encore une fois le code de cryptage et decryptage"
En attendant une réponse favorable,je vous prie d'agréer,Monsieur,l'expression de mon profond respect.
voila les 3 codes:
/////////////code pour le serveur///////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class serverChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port to the PDA client
// Sockets
ServerSocket serverSocket = null; // ServerSocket
//listening to the Client
Socket clientSocket = null; // Socket with Client
// Inout/Output for PDA Client
BufferedReader isClient = null;
PrintWriter osClient = null;
// Strings
String msg_String = null;
int msg_hash = 0;
int i = 0;
int Clientconnected = 0; // Connection marker
/********End declarations*********/
/****************Server Socket Creation**********/
System.out.print("\nCreation of the ServerSocket\nlistening to port 3000 \nfor client.");
try {
System.out.print(".");
serverSocket = new ServerSocket(port);
//Socket // listening on port 3000
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("...failed.\nProblem in the creation of the ServerSocket: " +e);
System.exit(1);
}
try {
clientSocket = serverSocket.accept();
Clientconnected = 1;
}
catch (IOException e) {
System.out.println("Unable to deal with BufferedReader and PrintWriter for the clientSocket : " +e);
System.exit(1);
}
/***************End of creation of Sockets*******/
try {
isClient = new BufferedReader(new InputStreamReader(clientSocket.
getInputStream()));
osClient = new PrintWriter (clientSocket.getOutputStream());
}
catch (IOException e) {
System.out.println("Cant't deal with the streams : " + e);
}
while (true) {
try {
msg_String = isClient.readLine();
System.out.println("String from the client : " + msg_String);
}
catch (IOException e) {
System.out.println("Couldn't get I/O for the connection to: ");
System.exit(1);
}
if (msg_String.trim().equals("/bye")) {
Clientconnected = 0;
clientSocket.close();
serverSocket.close();
System.exit(0);
}
if (Clientconnected == 1) {
try {
System.out.print("\nComputing...");
msg_hash = msg_String.hashCode();
System.out.print("done");
osClient.println(msg_hash);
osClient.flush(); // put it onto the network
System.out.print("...and sent.\n");
} //try
catch (Exception e) {
System.out.println(e);
System.exit(1);
} // catch
} // if Clientconnected
} // while
// System.exit(0);
} // void main
} // PDAServer class
////////////code pour client//////////////////
import java.io.*; // for input output
import java.lang.*; // for Threads
import java.net.*; // sockets
public class clientChat {
public static void main(String args[]) throws IOException {
/*******Declarations**********/
// Ports and Hosts
int port = 3000; // port
String myHost = "localhost";
// Sockets
Socket clientSocket = null;
// Inout/Output for PDA Client
BufferedReader isClient = null;
PrintWriter osClient = null;
BufferedReader readfromline = null;
// Strings
String myString = null;
String sString = null;
int i = 0; // Translation counter
int Clientconnected = 0; // Connection marker
/********End declarations*********/
try {
System.out.print("\nClient.");
clientSocket = new Socket(myHost, port);
System.out.print("..started.\n\n");
}
catch (IOException e) {
System.out.print("..failed.\nProblem in the creation of the Socket : " + e);
System.exit(1);
} //catch
try {
osClient = new PrintWriter(clientSocket.getOutputStream());
isClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
readfromline = new BufferedReader(new InputStreamReader(System.in));
}
catch (IOException e) {
System.out.println("Can't deal with the streams... : " + e);
} //catch
try {
while (true) {
myString = readfromline.readLine();
if (myString.trim().equals("/bye")) {
osClient.println("/bye");
osClient.flush();
clientSocket.close();
System.exit(1);
}
osClient.println(myString); // Write it
osClient.flush(); // put it onto the network
System.out.println("\nSending...: '" + myString + "' ...done.");
myString = isClient.readLine();
System.out.println("From server :-[===> " + myString + "\n");
} //while
} //try
catch (Exception e) {
System.out.println("Exception while sending data" + e);
System.exit(1);
} // catch
System.out.println("Closing connection to client");
// System.exit(0);
} // void main
} // clientChat class
////////////code pour cryptage et decryptage/////////
import java.security.*;
import javax.crypto.*;
// encrypt and decrypt using the DES private key algor
public class PrivateExemple {
public static void main(String[] args) throws Exception {
// check args and get plaintext
//byte[] plainText = args[0].getBytes("UTF8");
String ss = "je suis un marocain";
byte[] plainText = ss.getBytes();
// get a DES private key
System.out.println("\nStart generating DES key");
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
keyGen.init(56);
Key key = keyGen.generateKey();
System.out.println("Finish generating DES key");
// get a DES cipher object and print the provide
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
System.out.println("\n" + cipher.getProvider().getInfo());
// encrypt using the key and the plaintext
System.out.println("\nStart encryption");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] cipherText = cipher.doFinal(plainText);
System.out.println("Finish encryption: ");
System.out.println(new String(cipherText, "UTF8"));
// decrypt the ciphertext using the same key
System.out.println("\nStart decryption");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] newPlainText = cipher.doFinal(cipherText);
System.out.println("Finish decryption: ");
System.out.println(new String(newPlainText, "UTF8"));
}
}
mon msn est:kamal_tayri@hotmail.com
et merci beaucoup
27 avril 2006 à 05:47
5 mars 2006 à 17:57
5 mars 2006 à 17:22
Qu'est ce qu'il ne marche pas ?
5 mars 2006 à 15:46
28 févr. 2006 à 17:25
et client.jar
mais rien ne se passe .
ça marche pa chez moi
5 févr. 2006 à 10:17
le java est-il activé ?
Ce que tu décris MUAD-DIB, c'est la même chose que si on a pas executer le fichier serveur/serveur.jar
Bonne chance
5 févr. 2006 à 08:55
Je pense faire une révision au mois de mars...
D'ici là,
Bon dimanche à tous
GillesWebmaster
4 févr. 2006 à 23:16
4 févr. 2006 à 23:08
Avez-vous pensez à executer le serveur ?
4 févr. 2006 à 22:59
8 janv. 2006 à 20:49
Mais il est vrai qu'une amélioration s'imposera..
Bonne prog !
GillesWebmaster
8 janv. 2006 à 20:45
La présentation est un petit detail par rapport au code
Je trouve que c'est pas mal pour une première source (j'en ai pas publié encore !)
bonne prog !
8 janv. 2006 à 20:15
Bonne journée
8 janv. 2006 à 03:02
bonne prog !