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
|
public void ServFonct() {
int port=6500;
ServerSocket ss;
Socket s;
try{
ss=new ServerSocket(port);
while(true){
s=ss.accept();
InputStreamReader isr;
isr=new InputStreamReader(s.getInputStream());
BufferedReader in=new BufferedReader(isr);
PrintStream out=new PrintStream(s.getOutputStream());
//PrintWriter out1=new PrintWriter(s.getOutputStream(),true);
String ch=in.readLine();
trecu.append("\n>>>> "+ch);
out.flush();
s.close();
}
}catch(IOException iu){}
}
/////////***********************
void envoyer(){
int port=6500;
Socket s;
try{
s=new Socket("ip",port); ///ip je le recupere depuis le serveur
InputStreamReader isr;
isr=new InputStreamReader(s.getInputStream());
BufferedReader in=new BufferedReader(isr);
PrintWriter out1=new PrintWriter(s.getOutputStream(),true);
String ch=tenvoi.getText();
out1.write(ch);
s.close();
}catch(IOException iu){
System.out.println("Erreur:"+iu.getMessage());
JOptionPane.showMessageDialog(this,"Erreur: ip not connect","Message d'erreur",JOptionPane.ERROR_MESSAGE);
}
}
//////////////////////////////////////////
private JButton getBenvoi() {
if (benvoi == null) {
benvoi = new JButton();
benvoi.setText("Envoyer");
benvoi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("actionPerformed()");
envoyer();
}
});
}
return benvoi;
}
//////////////////*****************************
public static void main(String[] args) {
new ClServ().ServFonct();
//new ClServ().envoyer();
} |
Partager