bonjours tout le monde je suis debutant en tous qui est lié au java .La je suis entrain de faire un programme constituer d'un client et d'un serveur qui echange entre eu les information mais ca roule pas et j'arrive pas a trouver le probleme!!!

le code du client
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    import java.io.DataInputStream;
    import java.io.PrintStream;
    import java.net.Socket;
 
    public class Client {
      private Socket socket;
      private String host;
      private int port;
      private java.util.Vector albums = new java.util.Vector();
      private DataInputStream input;
      private PrintStream output;
 
      public Client(String h, int p) throws java.io.IOException {
        String data[] = new String[4];
        java.util.StringTokenizer tokens;
        String tmp;
        int x;
 
        host = h;
        port = p;
        socket = new Socket(host, port);
        input = new DataInputStream(socket.getInputStream());
        output = new PrintStream(socket.getOutputStream());
        tmp = input.readLine();
        try {
          x = Integer.parseInt(tmp);
        }
        catch( NumberFormatException e ) {
          throw new java.io.IOException("Communication error, invalid " +
                                        "number of albums.");
        }
        while( x-- > 0 ) {
          tmp = input.readLine();
          tokens = new java.util.StringTokenizer(tmp, ":");
          if( tokens.countTokens() != 4 ) {
            throw new java.io.IOException("Invalid album format.");
          }
          for(int i=1; i<=4; i++) data[i] = tokens.nextToken();
          albums.addElement(data);
        }
      }
 
      public synchronized void close() throws java.io.IOException {
        output.println("exit");
        socket.close();
      }
 
      public String[][] getAlbums() {
        String album_data[][];
 
        synchronized(albums) {
          album_data = new String[albums.size()][];
          albums.copyInto(album_data);
          return album_data;
        }
      }
 
      public synchronized void purchaseAlbum(String id, String cc)
      throws java.io.IOException {
        String tmp;
 
        output.println("purchase " + id + " " + cc.trim());
        tmp = input.readLine();
        if( tmp.equals("ok") ) return;
        else throw new java.io.IOException(tmp);
      }
    }
le code du serveur

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    import java.net.Socket;
    import java.net.ServerSocket;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
 
    public class Server extends Thread {
      private Connection connection;
      private Socket socket;
 
      public Server(Socket sock, Connection conn) {
        socket = sock;
        connection = conn;
      }
 
      public void run() {
        java.io.DataInputStream input;
        java.io.PrintStream output;
 
        try {
          String tmp;
          java.util.StringTokenizer tokens;
          java.util.Vector albums = new java.util.Vector();
          boolean transacting = true;
          Statement statement;
          ResultSet result_set;
 
          input = new java.io.DataInputStream(socket.getInputStream());
          output = new java.io.PrintStream(socket.getOutputStream());
          statement = connection.createStatement();
          result_set = statement.executeQuery("SELECT album_id, artist, title, "+
                                              &quo t;price " +
                                             & nbsp;"FROM album ");
          while( result_set.next() ) {
            String id, artist, title, price;
 
            id = result_set.getString(1);
            artist = result_set.getString(2);
            title = result_set.getString(3);
            price = result_set.getString(4);
            albums.addElement(id + ":" + artist + ":" + title + ":" + price);
          }
          output.println(albums.size());
          for(int i = 0; i<albums.size(); i++)
            output.println((String)albums.elementAt(i));
          while( transacting ) {
            tmp = input.readLine();
            tokens = new java.util.StringTokenizer(tmp);
            tmp = tokens.nextToken();
 
            if( tmp.equals("exit") ) {
              transacting = false;
            }
            else if( tmp.equals("purchase") ) {
              String credit_card;
              String id;
 
              if( tokens.countTokens() != 2 ) {
                output.println("error Invalid command");
                socket.close();
                return;
              }
              id = tokens.nextToken();
              credit_card = tokens.nextToken();
              statement = connection.createStatement();
              statement.executeUpdate("INSERT INTO purchase (" +
                                      "credit_card, album) " +
                                      "VALUES('" + credit_card + "', '" +
                                      id + "')");
              output.println("ok");
            }
          }
        }
        catch( Exception e );
        finally {
          try {
            socket.close();
          }
          catch( java.io.IOException e );
         }
      }
 
      static public void main(String args[]) {
        ServerSocket port_socket;
        String driver;
        String url;
        int port;
 
        if( args.length != 3 ) {
          System.err.println("Syntax: java Server <JDBC driver> <JDBC URL> " +
                             "<port>");
          System.exit(-1);
          return;
        }
        driver = args[0];
        url = args[1];
        try {
          port = Integer.parseInt(args[2]);
        }
        catch( NumberFormatException e ) {
          System.err.println("Invalid port number: " + args[2]);
          System.exit(-1);
          return;
        }
        try {
          port_socket = new ServerSocket(port);
        }
        catch( java.io.IOException e ) {
          System.err.println("Failed to listen to port: " + e.getMessage());
          System.exit(-1);
          return;
        }
        while( true ) {
          try {
            Connection conn;
            Server server;
            Socket client_sock = port_socket.accept();
 
            conn = java.sql.DriverManager.getConnection(url, "user", "pass");
            server = new Server(client_sock, conn);
            server.start();
          }
          catch( java.io.IOException e ) {
            System.err.println("Connection failed.");
          }
          catch( java.sql.SQLException e ) {
            System.err.println("Failed to connect to database.");
          }
        }
      }
    }

merci d'avance