-
probleme with my code
i'm doing this project
the patient process sends a request to a server process over a socket write to that request is a process over a socket donor, the donor process receives the client request, it sends a message to the client
the client checks whether there 's got a message
the problem that the donor remains blocked there is no treatment
patient process
Code:
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();
}
}
proccess serveur
[CODE]
/*
* 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 connexionversdonneurtypecritique()throws IOException
{
String host="127.0.0.1";
donsoc = new Socket (host , 2000) ;
OutputStream ecriture = donsoc.getOutputStream() ;
System.out.println("demandeversledonneur le malade est de type critique");
PrintWriter out = new PrintWriter(ecriture);
out.println("maladecritique");
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("maladecritique"))
{
this.connexionversdonneurtypecritique();
}
}
}
public static void main (String args[]) throws IOException
{ serveur s=new serveur();
s.connexion();
s.reception();
}
}
process donneur
Code:
/*
* 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 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);
InputStream lecture= soc.getInputStream ();
System.out.println(lecture);
BufferedReader entree = new BufferedReader (new InputStreamReader (lecture)) ;
String message =entree.readLine();
System.out.println(message);
if (message.equals("maladecritique"))
{
orgvit=1;
this.affection();
}
}
}
public void affection () throws IOException
{
if (orgvit==1)
{OutputStream ecriture = soc.getOutputStream() ;
PrintWriter out = new PrintWriter(ecriture);
System.out.println("affectiond'un organe vital");
out.println("af");
out.flush();
}
}
public static void main(String[] args)throws IOException {
donneur d= new donneur();
d.connexion();
d.reception();
// TODO code application logic here
}
}
i've this message
serveur active sur port 2000
Socket[addr=/127.0.0.1,port=1351,localport=2000]
java.net.SocketInputStream@19821f
where is the problem
there is no send to the process malade
thank you