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
|
private void Ecoute()
{
try {
oreille=new ServerSocket (1234);
System.out.println("creation");
while (connection=true)
{
Socket client=oreille.accept();
// mise en attente d'une connexion
InputStream entrée=client.getInputStream();
OutputStream sortie=client.getOutputStream();
//lecture d'un entier
//int iClient=entrée.read();
//envoie d'un octet
//sortie.write(13);
//lecture d'une chaine
DataInputStream dataentrée=new DataInputStream(entrée);
String chaineClient=dataentrée.readLine();
//Scanner sc = new Scanner(System.in);
System.out.print(chaineClient);
//écriture d'une chaine
//PrintStream printsortie=new PrintStream (sortie);
//printsortie.write("la chaine que j'envoie au client");
client.close();
connection = false;
}
oreille.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("pas de connexion");}
}
//-------------------------------------------------------------
// GESTION DES INTERACTIONS
//-------------------------------------------------------------
class boutonEnvoyerListener implements ActionListener
{
private String AdresseIP;
private Socket s;
private OutputStream sortie;
public void actionPerformed(ActionEvent arg0)
{
TextBuffer += AdresseIp + " dit : " + TextIn.getText() + " \n";
//TextBuffer = <html><body>Ligne 1<br />Ligne 2</body></html>;
TextOut.setText(TextBuffer);
TextIn.setText("");
try {
oreille.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.AdresseIP = "192.168.0.2";
try
{
this.s=new Socket(AdresseIP,PortCom);
InputStream entree= s.getInputStream();
this.sortie= s.getOutputStream();
//this.EnvoyerMessage();
PrintStream PrintSortie=new PrintStream(sortie);
PrintSortie.println("coucou");
s.close();
}
catch(UnknownHostException e)
{
System.out.println("serveur introuvable");
}
catch(IOException e)
{
System.out.println("impossible de se connecter");
}
connection = true;
//Ecoute();
}
} |
Partager