bonsoir à tous le monde dans ce code le client envoie un message au serveur(en utilisant un socket)
le serveur envoie un message au donneur (en utilisant un socket)
je voudrais savoir comment je doit faire pour que le donneur envoie un message(en utilisant un socket ) sans avoir de conflit avec le socket du serveur
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
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package client;
 
/**
 *
 * @author adel
 */
import java.net.* ;
import java.io.* ;
public class client
{
        Socket soc;
 
 
 
        public void connexion() throws IOException
{
 
     String host="127.0.0.1";
    int port = 1000 ;
 
    soc = new Socket (host , port) ;
 
}
        public void demande () throws IOException
        {
           OutputStream ecriture = soc.getOutputStream() ;
 
    PrintWriter out = new PrintWriter(ecriture);
out.println("maladec");
out.flush();
        }
  public static void main (String args[]) throws IOException
 
 
  {client c=new client();
   c.connexion();
   c.demande();
 
  }
  }
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
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package serveur;
 
/**
 *
 * @author adel
 */
import java.io.* ;
import java.net.* ;
public class serveur
{
ServerSocket sersoc;
Socket soc; /*reception du client */
Socket donsoc /* connextion vers le le donneur */;
    public void connexion ()  throws IOException
    {
 
            sersoc = new ServerSocket (1000);;
    System.out.println ("serveur active sur port 1000" ) ;
    }
    public void connexionversdonneur()throws IOException
    {
        String host="127.0.0.1";
    donsoc = new Socket (host , 2000) ;
    OutputStream ecriture = donsoc.getOutputStream() ;
System.out.println("demandeduclient");
    PrintWriter out = new PrintWriter(ecriture);
out.println("demandeduclient");
out.flush();
 
    }
    public void  reception () throws IOException
    {
    while (true)
        {
         soc= sersoc.accept();
         InputStream lecture= soc.getInputStream ();
 
  BufferedReader entree = new BufferedReader (new InputStreamReader (lecture)) ;
 
      String message =entree.readLine();
 
      System.out.println(message);
      if (message.equals("maladec"))
      {
          String host="127.0.0.1";
    donsoc = new Socket (host , 2000) ;
    OutputStream ecriture = donsoc.getOutputStream() ;
 
    PrintWriter out = new PrintWriter(ecriture);
out.println("maladec");
out.flush();
 
 
    }
 
    }
    }
 public static void main (String args[]) throws IOException
  { serveur s=new serveur();
    s.connexion();
    s.reception();
 }
 }
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
 
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package donneur;
 
/**
 *
 * @author adel
 */
import java.io.* ;
import java.net.* ;
public class donneur {
ServerSocket serdon;
Socket soc;
int ressource1=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();
         InputStream lecture= soc.getInputStream ();
 
  BufferedReader entree = new BufferedReader (new InputStreamReader (lecture)) ;
 
      String message =entree.readLine();
 
      System.out.println(message);
      if (message.equals("maladec"))
      {System.out.println("prise en charge du malade");
 
 
    }
     }
     }
    public static void main(String[] args)throws IOException  {
      donneur d= new donneur();
      d.connexion();
      d.reception();
        // TODO code application logic here
    }
 
}