envoi serveur client impossible
classe du serveur:
Code:
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
|
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Ser2 extends JFrame{
static final int port =8080;
public static JTextField text1;public static JTextField text2;
public static JButton b2;
Socket soc;
BufferedReader plec;
PrintWriter pred;
public Ser2(){
super("Serveur");
Container c=getContentPane();
text1=new JTextField("");b2=new JButton ("gomi");text2=new JTextField("");
c.setLayout(null);
text1.setBounds(50,100, 200, 20); b2.setBounds(50,250, 50, 20);text2.setBounds(50,50, 200, 20);
c.add(text1);c.add(b2);c.add(text2);
setBounds(0, 0, 400, 400);
setVisible(true);
try { ServerSocket s = new ServerSocket(port);
soc = s.accept();
plec = new BufferedReader(new InputStreamReader(soc.getInputStream()));
pred = new PrintWriter(new BufferedWriter(new OutputStreamWriter(soc.getOutputStream())),true);
}
catch (IOException e2){System.out.println("erreur");}
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
class AL1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String str = text2.getText();
pred.println(str);}}
b2.addActionListener(new AL1());
while (true)
{try {String str = plec.readLine();
if (str.equals("END")==false)text1.setText(str);
else break;}catch (IOException e3){System.out.println("erreur");}
}
}} |
classe client:
Code:
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
| import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Ser2 extends JFrame{
static final int port =8080;
public static JTextField text1;public static JTextField text2;
public static JButton b2;
Socket soc;
BufferedReader plec;
PrintWriter pred;
public Ser2(){
super("Serveur");
Container c=getContentPane();
text1=new JTextField("");b2=new JButton ("gomi");text2=new JTextField("");
c.setLayout(null);
text1.setBounds(50,100, 200, 20); b2.setBounds(50,250, 50, 20);text2.setBounds(50,50, 200, 20);
c.add(text1);c.add(b2);c.add(text2);
setBounds(0, 0, 400, 400);
setVisible(true);
try { ServerSocket s = new ServerSocket(port);
soc = s.accept();
plec = new BufferedReader(new InputStreamReader(soc.getInputStream()));
pred = new PrintWriter(new BufferedWriter(new OutputStreamWriter(soc.getOutputStream())),true);
}
catch (IOException e2){System.out.println("erreur");}
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}});
class AL1 implements ActionListener {
public void actionPerformed(ActionEvent e) {
String str = text2.getText();
pred.println(str);}}
b2.addActionListener(new AL1());
while (true)
{try {String str = plec.readLine();
if (str.equals("END")==false)text1.setText(str);
else break;}catch (IOException e3){System.out.println("erreur");}
}
}} |
quand j'execute les 2 classes à part,ça marche.
Maintenant que veux créer 2 autre fenetres dans chacune un boutton.
j'ai mis un écouteur sur chaque boutton et au clique j'instancie la classe serveur ou clientà l'execution,j'ai mes 2 nouvelles fenetres,mais dès que je clique sur les boutton pr avoir les fenetre Cli2 et Ser2,ça bloque!!!!qlq1 peut me dire pk?
merci