L
Laco
Hi,
I have a problem sending data using socket and I still don't know
how to fix it. When I establish a connection and try to send a text
file, I miss the end of the file.
The number of bytes that I read from the file is correct. The problem
seems to be with: "oos.write(datos, 0, length);"
What I want to do is establish a connection between two applications and
send files. I tried with "java.util.zip.*;" too, and transfer using
GZIPOutputStream gzipout = new GZIPOutputStream(clientSocket.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(gzipout);
bud I had the same problems.
I don't know if I do something wrong or not, but if anyone can offer any
solutions I would be greatfull.
The code looks something like this:
private PrintWriter out = null;
private BufferedReader in = null;
....
out = new PrintWriter(_clientSocket.getOutputStream());
in = new BufferedReader(new InputStreamReader(_clientSocket.getInputStream()));
....
File fis = new File("file.txt");
FileInputStream origen = new FileInputStream(fis);
BufferedOutputStream gzipout = new BufferedOutputStream(clientSocket.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(gzipout);
byte datos[]=new byte[1024];
int length=0;
while((length=origen.read(datos,0,1024))!=-1) {
System.out.println(datos.toString()+" + "+length);
oos.write(datos, 0, length);
}
PD: Sorry for my english!
I have a problem sending data using socket and I still don't know
how to fix it. When I establish a connection and try to send a text
file, I miss the end of the file.
The number of bytes that I read from the file is correct. The problem
seems to be with: "oos.write(datos, 0, length);"
What I want to do is establish a connection between two applications and
send files. I tried with "java.util.zip.*;" too, and transfer using
GZIPOutputStream gzipout = new GZIPOutputStream(clientSocket.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(gzipout);
bud I had the same problems.
I don't know if I do something wrong or not, but if anyone can offer any
solutions I would be greatfull.
The code looks something like this:
private PrintWriter out = null;
private BufferedReader in = null;
....
out = new PrintWriter(_clientSocket.getOutputStream());
in = new BufferedReader(new InputStreamReader(_clientSocket.getInputStream()));
....
File fis = new File("file.txt");
FileInputStream origen = new FileInputStream(fis);
BufferedOutputStream gzipout = new BufferedOutputStream(clientSocket.getOutputStream());
ObjectOutputStream oos = new ObjectOutputStream(gzipout);
byte datos[]=new byte[1024];
int length=0;
while((length=origen.read(datos,0,1024))!=-1) {
System.out.println(datos.toString()+" + "+length);
oos.write(datos, 0, length);
}
PD: Sorry for my english!