Grazie per il consiglio
Non riesco a trovare conflitti..
Ecco il codice:
MainClass
codice:
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
SendFile obj=new SendFile("127.0.0.1");
CountDown ob=new CountDown(jLabel1);
obj.takeFile();
obj.start();
}
SendFile
codice:
package tesi;
public class SendFile extends Thread
{
String ip;
public SendFile(String ip)
{
this.ip=ip;
}
String text;
DataInputStream in1;
BufferedReader in;
FileInputStream fis;
File f;
Socket s1;
Socket s2;
//Mette in fis il file pronto per essere inviato
public void takeFile()
{
JFileChooser chooser = new JFileChooser();
int n = chooser.showOpenDialog(chooser);
if(n==JFileChooser.APPROVE_OPTION)
{
f = chooser.getSelectedFile();
try
{
fis = new FileInputStream(f);
}
catch (FileNotFoundException ex)
{
Logger.getLogger(SendFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
// Si connette al Server e invia il File
@Override
public void run()
{
try
{
s2 = new Socket (ip,5556);
//Invio al server il nome del File
OutputStream out2 = s2.getOutputStream();
PrintWriter alServer= new PrintWriter(out2,true);
String nome=f.getName();
alServer.println(nome);
// out2.close();
// s2.close();
System.out.println(nome);
byte[] buf = new byte[fis.available()];
s1 = new Socket (ip,5555);
// Invio l'intero flusso di bytes al server e chiudo file in ingresso flusso di comunicazione e socket
int read;
OutputStream out1 = s1.getOutputStream();
CountDown obj=new CountDown();
obj.start(); -------- ECCO QUI -----------
while ((read = fis.read(buf)) != -1)
{
out1.write(buf, 0, read);
}
fis.close();
out1.close();
s1.close();
}
catch (UnknownHostException ex)
{
Logger.getLogger(SendFile.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex)
{
Logger.getLogger(SendFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
La classe CountDown è quella già postata.