CHAT SIMPLE MODE GRAPHIQUE AVEC SELECTEUR D'IP ET CHOIX DE PSEUDO

mobilicorpus Messages postés 18 Date d'inscription mardi 3 mai 2005 Statut Membre Dernière intervention 5 mars 2006 - 8 janv. 2006 à 03:02
essmoez22 Messages postés 1 Date d'inscription mardi 2 février 2010 Statut Membre Dernière intervention 15 octobre 2010 - 15 oct. 2010 à 13:28
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/33602-chat-simple-mode-graphique-avec-selecteur-d-ip-et-choix-de-pseudo

essmoez22 Messages postés 1 Date d'inscription mardi 2 février 2010 Statut Membre Dernière intervention 15 octobre 2010
15 oct. 2010 à 13:28
mllmml
kamal_tayri Messages postés 7 Date d'inscription dimanche 16 avril 2006 Statut Membre Derniè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

// 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
kamal_tayri Messages postés 7 Date d'inscription dimanche 16 avril 2006 Statut Membre Derniè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

// 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
root2004 Messages postés 6 Date d'inscription mercredi 27 octobre 2004 Statut Membre Derniè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és 496 Date d'inscription mercredi 30 juin 2004 Statut Membre Dernière intervention 29 juillet 2009 1
5 mars 2006 à 17:57
Je me demande quelle est votre version de java?
mobilicorpus Messages postés 18 Date d'inscription mardi 3 mai 2005 Statut Membre Derniè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és 496 Date d'inscription mercredi 30 juin 2004 Statut Membre Dernière intervention 29 juillet 2009 1
5 mars 2006 à 15:46
alors c'est votre version de Java
obydissonn Messages postés 2 Date d'inscription mardi 19 juillet 2005 Statut Membre Dernière intervention 28 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és 18 Date d'inscription mardi 3 mai 2005 Statut Membre Derniè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és 496 Date d'inscription mercredi 30 juin 2004 Statut Membre Dernière intervention 29 juillet 2009 1
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és 103 Date d'inscription lundi 9 avril 2001 Statut Membre Dernière intervention 16 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és 18 Date d'inscription mardi 3 mai 2005 Statut Membre Dernière intervention 5 mars 2006
4 févr. 2006 à 23:08
muad-dib :

Avez-vous pensez à executer le serveur ?
cs_muad-dib Messages postés 103 Date d'inscription lundi 9 avril 2001 Statut Membre Dernière intervention 16 juillet 2008
4 févr. 2006 à 22:59
marche po chez moi
GillesWebmaster Messages postés 496 Date d'inscription mercredi 30 juin 2004 Statut Membre Dernière intervention 29 juillet 2009 1
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és 18 Date d'inscription mardi 3 mai 2005 Statut Membre Derniè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és 496 Date d'inscription mercredi 30 juin 2004 Statut Membre Dernière intervention 29 juillet 2009 1
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és 18 Date d'inscription mardi 3 mai 2005 Statut Membre Derniè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

bonne prog !
Rejoignez-nous