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
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package donneur;
/**
*
* @author adel
*/
import java.io.* ;
import java.net.* ;
class lanceur extends Thread
{
private Socket client;
static int organevit=0;
public lanceur(Socket s )
{
client=s;
}
public void run()
{
try
{ System.out.println("Le client numéro est connecté !");
System.out.println(organevit);
if (organevit==1)
{
OutputStream ecriture = client.getOutputStream() ;
PrintWriter out = new PrintWriter(ecriture);
out.println("affectionmaladecritique");
out.flush();
//out.close();
}
if (organevit==0)
{
InputStream lecture= client.getInputStream ();
BufferedReader entree = new BufferedReader (new InputStreamReader (lecture));
String message = entree.readLine();
System.out.println(message);
if (message.equals("organecritique"))
{
organevit=1;
}
}
client.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public class donneur {
ServerSocket serdon;
Socket soc;
int orgvit=0;
int orgnovit=0;
public void connexion () throws IOException
{
serdon = new ServerSocket (2000);
System.out.println ("serveur active sur port 2000" ) ;
}
/**
* @param args the command line arguments
*/
public void reception () throws IOException
{
while (true)
{
soc= serdon.accept();
System.out.println(soc);
Thread t = new Thread(new lanceur(soc));
t.start();
}
}
public static void main(String[] args) throws IOException {
donneur d= new donneur();
d.connexion();
d.reception();
// TODO code application logic here
}
} |
Partager