ce programme consiste de 3 partie un dans le serveur et l'autre dans un autre serveur de backup et le dernier dans la partie client. c un programme qui fais le backup et la recuperation dans fichier quant on le trouve pas chez le serveur sans que le client notice cette faille
voila le code veuiller m'aider a le corriger:
Coté Serveur
import java.io.*;
import java.net.*;
import java.net.Socket;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
class Serveur
{
public static void main(String []args)
{
ServerSocket ss;
Socket sc;
try
{
ss=new ServerSocket(2000);
sc=ss.accept();
while(true)
{
byte[] sendBuffer=new byte [500];
String path="cmes document";
sendBuffer=path.getBytes();
OutputStream out=sc.getOutputStream();
int i;
int j=sendBuffer.length;
for( i=0;i<j;i++)
{
out.write(sendBuffer);
out.flush();
}
try
{
sleep((int)(Math.random()*7200));
}
catch(UnsupportedOperationException e) {
System.out.println(e);
}
}
}
catch(IOException e)
{
}
}
private static void sleep(int i) {
throw new UnsupportedOperationException("Not yet implemented" );
}
}
class Serveur_Client
{
public static void main( String [] args)
{
Socket c;
ServerSocket s;
try
{
s=new ServerSocket(200);
while(true)
{
c = s.accept();
Connexion x= new Connexion(c);
x.start() ;
}
}
catch(IOException e) { }
}
}
class Connexion extends Thread
{
Socket c;
Connexion(Socket c)
{
this.c=c;
}
public void run()
{
try
{
File donnee= new File("c:" );
InputStream in=c.getInputStream();
String st= in.toString ();
ResultSet onnee=recherche(st);
Byte [] sendBuffer =new Byte[500];
sendBuffer = onnee.getByte(onnee)
OutputStream out=c.getOutputStream();
sendBuffer[i]=donnee.Byte
sendBuffer =(Byte)chara(donnee)
for(int i; i<sendBuffer.length;i++)
{
out.write(sendBuffer[i]);
out.flush(); // pour garentir l’envoie
}
c.close();
}
catch(IOException e) { }
}
public ResultSet recherche(String nom)
{
try
{
Class.forName("com.mysql.jdbc.Driver" );
String path="cmes document";
Connection conn=DriverManager.getConnection(path);
// creation d’un objet statement
Statement state=conn.createStatement();
// L’objet Resultset contient le résultat de la requête SQL
ResultSet result=state.executeQuery("select * from nom_base where nom_fich=nom" );
if (result == null)
result=récupère(nom);
return result;
} catch (Exception e) { }
} //fermeture de recherche
public ResultSet récupère (String doc)
{
Serveur2 a =new Serveur2(doc);
}
}//fermeture du class
class Serveur2
{
Serveur2(String doc)
{
this.doc=doc;
}
try
{
Socket sc;
sc= new Socket(InetAdress.getByName(‘’123.43.43.45’’),123);
PrintWriter fout= new PrintWriter(new OutputStreamWriter(sc.getOutputStream()));
fout.println(doc);
InputStream in=sc.getInputStream();
Byte [] receiveBuffer=new Byte [500];
while(true)
receiveBuffer=in.read();
return receiveBuffer;
}
catch(IOException e)
{
System.out.Println(e);
}
}
Coté Client
Class Client
{
Public static void main( String [] args)
{
Try
{
Socket c;
String nom_fich;
InetAdress serv=InetAdress.getByName(“193.34.32.45”);
C=new Socket(serv,2000);
OutputStream out=c.getOutputStream();
For(int i=0;i<nom_fich. Length;i++)
out.write((int)nom_fich.charAt[i]);
InputStream in=c.getInputStream();
While(int i=in.read()!=-1)
system.out.println((char)i);
c.close();
}
Catch(IoException e)
{
system.out.println(e);
} }
}
Coté serveur de backup
Public class ServClient
{
Public static void main(string []args)
{
Try
{ socket sc;
Sc=new socket(“nom-serv”,nport) ;
InputStream in=sc.getInputStream();
Byte[] receiveBuffer=new Byte[500];
While(true)
{
receiveBuffer=in.read();
string receive=new string(receiveBuffer.getData);
create new filesource=filesource;
filesource=new file(receive);
}
sc.close();
}catch(IOException e)
{
sendMail(
}
Void sendMail(String recipients [], String subject,String message ,String from)
{
// create some properties and get the default session
Session session=session.getDefaultInstance(“……….@hotmail .fr ‘’,null) ;
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain" );
Transport.send(msg);
}
}
Class lancementService
{
Public Static void main(string [] args)
{
ServerSocket ss;
Socket c;
Try
{
Ss=new ServerSocket (2300);
While(true)
{
C=ss.accept();
Connexion x =new Connexion();
x.start() ;
}
} catch(IOException e) { }
}
}
Class ServClient2
{
Public static void main(String [] args)
{
Socket sc;
ServerSocket ss;
Try
{
ss=new ServerSocket(2001);
While(true)
{
sc=ss.accept();
Connexion x= new connexion( c);
x.start() ;
}
}
Catch(IOException e) { }
}
}
}
Class Connexion extends thread
{
Socket c;
Connexion(Socket c)
{
This.c=c;
}
Public void run()
{
Try
{
File donnee= new File();
BufferedReader fin= new BufferReader(new inputStreamReader(c.getInputStream()));
donnee= recherche(fin);
OutputStream out=c.getOutputStream();
Byte [] sendBuffer = new Byte [500];
sendBuffer = donne.getBytes();
for(int I; i<sendBuffer.length();i++)
{
out.write(sendBuffer);
out.flush(); // pour garentir l’envoie
}
c.close;
}
Catch(IOException e) { }
} //fermeture de run
Public void recherche(String nom)
{
Try
{
Class.forName(‘’ com.mysql.jdbc.Driver’’) ;
String path=’’c……..’’ ;
Connection conn=DriverManager.getConnection(path);
// creation d’un objet statement
Statement state=conn.createStatement();
// L’objet Resultset contient le résultat de la requête SQL
ResultSet result = State.executeQuery (‘’ SELECT * FROM nom_base where nom_fich=nom ‘’);
Return result;
} catch (Exception e) { }
} //fermeture de recherche