IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Entrée/Sortie Java Discussion :

Socket ultra simple


Sujet :

Entrée/Sortie Java

  1. #1
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 3
    Points : 2
    Points
    2
    Par défaut Socket ultra simple
    Bonjour,

    je cherche à faire un petit script en java.
    il y a un serveur et un client sur 2 machines différente.

    je voudrais simplement vérifier la communication entre les deux machines.

    Est il possible de faire un script avec des socket tres tres simple.
    Le client envoie un charactere au serveur et le serveur lui en renvoie un autre.
    enfin pas de buffer, vraiment tres simple.

    dans le script client je voudrais choisir le port et l'ip pour le serveur(en tcp pour l'instant je ferrais l'udp après, si j'arrive avec tcp;-).

    je suis assez null en java et tous les exemples sur internet sont un peut trop compliqué. il y a bien un jeu d'instruction minimum pour faire une socket?

    merci

  2. #2
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 51
    Points : 28
    Points
    28
    Par défaut
    essayer ce code:
    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
     
    declaration:
    BufferedReader in;
    BufferedWriter out;
    String line;
    private Socket soc;
    ServerSocket ss;
    corp du programme:              
     try{
    ss = new ServerSocket(5555);
    soc = ss.accept();
     
    out.println("-Bonjour > "+InetAddress.getLocalHost().getHostAddress()+"\nVous êtes connecté\n");
    out.flush();
    out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(soc.getOutputStream())),true);
    out.flush();
    in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
                    while ((line = in.readLine()) != null)
                    {
                        out.println("-Message reçu\n");
                        out.flush();
     
                        if(line.equals("exit"))
                        {
                            try
                            {
                                out.println("Au revoir "+nbrclient+" "+InetAddress.getLocalHost().getHostAddress()+"\nvous êtes déconnecté");
                                out.flush();
     
                                in.close();
                                out.close();
                                soc.close();
     
                            }
                            catch(IOException e) {System.out.println(e.getMessage());}
                        }
    tu vérifie si ce code marche ou non, à partir d'une console msdos: démarrer>exécuter et tu tape la commande telnet localhost 5555
    j'espère que cela vous aide
    tu peut voir ce lein aussi, c'est très utile:
    http://pages.univ-nc.nc/~touraivane/...00000000000000

  3. #3
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Mars 2011
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    bonjour,

    le problème c'est que j'ai fait une interface graphique avec netbeans.

    le code s'exécute quand j'appuis sur un bouton.

    mon code fait c'est ca:
    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
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
     
    /*
     * ChargenView.java
     */
    package chargen;
    import java.io.*;
    import java.net.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import org.jdesktop.application.Action;
    import org.jdesktop.application.ResourceMap;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import org.jdesktop.application.TaskMonitor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    import javax.swing.Icon;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
     
     
     
    public class ChargenView extends FrameView {
     
        public ChargenView(SingleFrameApplication app) {
            super(app);
     
            initComponents();
     
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);
     
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
        }
     
        @Action
        public void showAboutBox() {
            if (aboutBox == null) {
                JFrame mainFrame = ChargenApp.getApplication().getMainFrame();
                aboutBox = new ChargenAboutBox(mainFrame);
                aboutBox.setLocationRelativeTo(mainFrame);
            }
            ChargenApp.getApplication().show(aboutBox);
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
     
            mainPanel = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jComboBox1 = new javax.swing.JComboBox();
            jLabel1 = new javax.swing.JLabel();
            jToggleButton1 = new javax.swing.JToggleButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            menuBar = new javax.swing.JMenuBar();
            javax.swing.JMenu fileMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
            javax.swing.JMenu helpMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
            statusPanel = new javax.swing.JPanel();
            javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
            statusMessageLabel = new javax.swing.JLabel();
            statusAnimationLabel = new javax.swing.JLabel();
            progressBar = new javax.swing.JProgressBar();
     
            mainPanel.setAutoscrolls(true);
            mainPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
            mainPanel.setFocusable(false);
            mainPanel.setName("mainPanel"); // NOI18N
     
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(chargen.ChargenApp.class).getContext().getResourceMap(ChargenView.class);
            jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
            jButton1.setName("jButton1"); // NOI18N
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
                }
            });
     
            jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
            jButton2.setName("jButton2"); // NOI18N
            jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton2MouseClicked(evt);
                }
            });
     
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "TCP", "UDP" }));
            jComboBox1.setName("jComboBox1"); // NOI18N
     
            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N
     
            jToggleButton1.setText(resourceMap.getString("jToggleButton1.text")); // NOI18N
            jToggleButton1.setName("jToggleButton1"); // NOI18N
            jToggleButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jToggleButton1MouseClicked(evt);
                }
            });
     
            jScrollPane1.setName("jScrollPane1"); // NOI18N
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jTextArea1.setName("jTextArea1"); // NOI18N
            jScrollPane1.setViewportView(jTextArea1);
     
            jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
            jTextField1.setName("jTextField1"); // NOI18N
     
            jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
            jTextField2.setName("jTextField2"); // NOI18N
     
            jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
            jLabel2.setName("jLabel2"); // NOI18N
     
            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
            mainPanel.setLayout(mainPanelLayout);
            mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGap(73, 73, 73)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel1))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                    .addContainerGap(77, Short.MAX_VALUE)
                                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(mainPanelLayout.createSequentialGroup()
                                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                            .addComponent(jButton2)
                                            .addGap(13, 13, 13)))))
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGap(104, 104, 104)
                                    .addComponent(jButton1))
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGap(4, 4, 4)
                                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                                        .addGroup(mainPanelLayout.createSequentialGroup()
                                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(jToggleButton1)))))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addGap(59, 59, 59)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(69, Short.MAX_VALUE))
            );
            mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                    .addGap(45, 45, 45)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jToggleButton1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton2)
                        .addComponent(jButton1))
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(19, 19, 19))
            );
     
            menuBar.setName("menuBar"); // NOI18N
     
            fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
            fileMenu.setName("fileMenu"); // NOI18N
     
            javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(chargen.ChargenApp.class).getContext().getActionMap(ChargenView.class, this);
            exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
            exitMenuItem.setName("exitMenuItem"); // NOI18N
            fileMenu.add(exitMenuItem);
     
            menuBar.add(fileMenu);
     
            helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
            helpMenu.setName("helpMenu"); // NOI18N
     
            aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
            aboutMenuItem.setName("aboutMenuItem"); // NOI18N
            helpMenu.add(aboutMenuItem);
     
            menuBar.add(helpMenu);
     
            statusPanel.setName("statusPanel"); // NOI18N
     
            statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
     
            statusMessageLabel.setName("statusMessageLabel"); // NOI18N
     
            statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
     
            progressBar.setName("progressBar"); // NOI18N
     
            javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
            statusPanel.setLayout(statusPanelLayout);
            statusPanelLayout.setHorizontalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(statusMessageLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 251, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusAnimationLabel)
                    .addContainerGap())
            );
            statusPanelLayout.setVerticalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusMessageLabel)
                        .addComponent(statusAnimationLabel)
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(3, 3, 3))
            );
     
            setComponent(mainPanel);
            setMenuBar(menuBar);
            setStatusBar(statusPanel);
        }// </editor-fold>                        
     
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
            // TODO add your handling code here:
    //####################################################################
    //####################################################################
    //##########################   Client     ############################
    //####################################################################
    //####################################################################
     
     
     
     
     
     
        }
    //####################################################################
    //####################################################################
    //########################## fin  Client  ############################
    //####################################################################
    //####################################################################
        }                                     
     
        private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {                                      
            // TODO add your handling code here:
    //####################################################################
    //####################################################################
    //##########################   Serveur    ############################
    //####################################################################
    //####################################################################
     
     
     
       }
     
     
        }                                     
    //####################################################################
    //####################################################################
    //##########################  fin serveur ############################
    //####################################################################
    //####################################################################
     
        private void jToggleButton1MouseClicked(java.awt.event.MouseEvent evt) {                                            
            // TODO add your handling code here:
            String chaine;
            String proto;
            int i;
     
            chaine = jTextField1.getText();
     
            proto = "" + jComboBox1.getItemAt(jComboBox1.getSelectedIndex());
            jTextArea1.append("Proto:" +proto);
            jTextArea1.append("\n");
            jTextArea1.append("Port:" +chaine);
        }                                           
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JToggleButton jToggleButton1;
        private javax.swing.JPanel mainPanel;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JProgressBar progressBar;
        private javax.swing.JLabel statusAnimationLabel;
        private javax.swing.JLabel statusMessageLabel;
        private javax.swing.JPanel statusPanel;
        // End of variables declaration                   
     
        private final Timer messageTimer;
        private final Timer busyIconTimer;
        private final Icon idleIcon;
        private final Icon[] busyIcons = new Icon[15];
        private int busyIconIndex = 0;
     
        private JDialog aboutBox;
    }
    donc au niveau des commentaires client et serveur je voudrais intégrer le code des sockets.

    le lien http://pages.univ-nc.nc/~touraivane/...00000000000000

    est tres bien mais je ne comprend pas, il y a plein de bout de code et je ne sais pas quoi placer et ou.

  4. #4
    Nouveau membre du Club
    Inscrit en
    Mai 2010
    Messages
    51
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 51
    Points : 28
    Points
    28
    Par défaut
    tu peux t'aider du ActionListener:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    tonbouton.addActionListener(new ouvrirSocket());
    puis:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    class ouvrirSocket implements ActionListener {
     
            public void actionPerformed(ActionEvent e) {
     
    //insérer code
     
    }
    }
    et dedans tu mets ton code et n'oublie pas bien sur de l'entourer avec le fameux try-catch
    j'espère que cela t'aide

Discussions similaires

  1. un algo de HASH ultra simple ?
    Par Seb.26 dans le forum Algorithmes et structures de données
    Réponses: 9
    Dernier message: 10/09/2010, 01h22
  2. Réponses: 5
    Dernier message: 20/05/2010, 18h08
  3. Initiation au socket (programme simple)
    Par moumine dans le forum Réseau/Web
    Réponses: 0
    Dernier message: 16/07/2009, 11h19
  4. [SQL] Moteur de recherche ultra simple ?
    Par Jiraiya42 dans le forum PHP & Base de données
    Réponses: 19
    Dernier message: 12/10/2006, 18h03
  5. [Delphi] Cherche moteur 3D ultra simple à utiliser
    Par Matt2094 dans le forum Moteurs 3D
    Réponses: 3
    Dernier message: 22/05/2006, 09h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo