begin process at 2010 02 09 12:13:38
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

J++

 > CHAT TCP TRES SIMPLE À COMPRENDRE

CHAT TCP TRES SIMPLE À COMPRENDRE


 Information sur la source

Note :
10 / 10 - par 2 personnes
10,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :J++ Niveau :Débutant Date de création :18/02/2005 Vu / téléchargé :13 349 / 2 247

Auteur : ouassit

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

ce code contien un client et un serveur le client envoie des message au serveur et le serveur accepte la connexion et  lui repond dans la  console,et ainsi de suite de manière  périodiquement . je vais l'améliorer dans les jour qui viennent



 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   client tcp
    • Class1.classTélécharger ce fichier [Réservé aux membres club]1 596 octets
    • Class1.javaTélécharger ce fichier [Réservé aux membres club]Voir ce fichier1 351 octets
    • Clavier.classTélécharger ce fichier [Réservé aux membres club]1 262 octets
    • client tcp.exeTélécharger ce fichier [Réservé aux membres club]10 752 octets
    • client tcp.slnTélécharger ce fichier [Réservé aux membres club]Voir ce fichier517 octets
    • client tcp.suoTélécharger ce fichier [Réservé aux membres club]4 608 octets
    • client tcp.vjpTélécharger ce fichier [Réservé aux membres club]4 540 octets
    • codebase.datTélécharger ce fichier [Réservé aux membres club]89 octets
  •   serveur tcp
    • Class1.classTélécharger ce fichier [Réservé aux membres club]1 702 octets
    • Class1.javaTélécharger ce fichier [Réservé aux membres club]Voir ce fichier1 440 octets
    • Clavier.classTélécharger ce fichier [Réservé aux membres club]1 263 octets
    • codebase.datTélécharger ce fichier [Réservé aux membres club]90 octets
    • serveur tcp.exeTélécharger ce fichier [Réservé aux membres club]11 264 octets
    • serveur tcp.slnTélécharger ce fichier [Réservé aux membres club]Voir ce fichier519 octets
    • serveur tcp.suoTélécharger ce fichier [Réservé aux membres club]4 608 octets
    • serveur tcp.vjpTélécharger ce fichier [Réservé aux membres club]4 546 octets

Télécharger le zip


 Sources du même auteur

Source avec Zip SIMULATION DE MODULATION
Source avec Zip SIMULATION DE L ALGORITHME DE DIJKSTRA
Source avec Zip SÉRIALISATION

 Sources de la même categorie

Source avec Zip Source avec une capture GESTION DES SYSTÈMES DISTRIBUÉS par 2mohamed2
Source avec Zip Source avec une capture EXEMPLE DE GESTION DE FICHE DOCUMENTAIRE SOUS WINDOWS par chtitfred
CONSOLE STANDARD IMPLEMENTABLE AVEC UN INPUTLOGLISTENER par broumbroum
Source avec Zip Source avec une capture MANIPULATION DE FICHIER XML par hedi_tounsi
Source avec Zip GESTION D'UN GARAGE par krokro1

Commentaires et avis

Commentaire de james04ma le 05/03/2005 14:45:12

eviter d introduire tes tps ici monsieur oussite et essyer de faire qlq chose de nouveau ;-)

Commentaire de fuscage le 20/05/2005 10:40:29

slt, cmt a tu fait l'executable???

Commentaire de kamal_tayri le 01/05/2006 16:38:56

salut Monsieur,
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

Commentaire de Faxanadu le 07/06/2006 17:02:50

chez moi je reussi pas la le faire fonctionner

 Ajouter un commentaire




Nos sponsors


Appels d'offres

Sondage...

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 2,044 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales