Galera tenho que fazer uma comunicação TCP/IP. Peguei o codigo desse topico e adaptei. O arquivo aparece criado no cliente/servidor. Porém sem conteúdo ! . Exemplo se encaminho um .txt o conteúdo anotado não aparece; Só o .txt vazio. O mesmo acontece quando encaminho um .jpg, o arquivo é criado , mas sem conteúdo ! Alguém poderia me ajudar ? Obrigado
[code] Servidor
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.;
import java.io.;
class Server {
public static void main(String[] argv) throws Exception {
try {
ServerSocket welcomeSocket = new ServerSocket (6789);
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
String fName = inFromClient.readLine();
System.out.println(fName);
File f1 = new File("/users/adsonAlves/desktop/trabalho redes/envio de arquivo/" + fName);
FileOutputStream out = new FileOutputStream(f1);
int tamanho = 4096; // buffer de 4KB 4096
byte[] buffer = new byte[tamanho];
out.flush();
} catch (IOException e) {
}
}
[/code]
[code]
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.Scanner;
import java.io.;
import java.net.;
class Client {
public static void main(String argv[]) throws Exception
{
Scanner tc = new Scanner(System.in);
Socket clientSocket= new Socket(“192.168.1.105”,6789);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
System.out.println(“File:”);
String fName = tc.nextLine();
File C = new File("/users/adsonAlves/desktop/trabalho redes/envio de arquivo/" + fName);
FileInputStream in = new FileInputStream©;
OutputStreamWriter osw = new OutputStreamWriter(outToServer);
BufferedWriter writer = new BufferedWriter(osw);
writer.write(C.getName() + "\n");
writer.flush();
int tamanho = 4096; // buffer de 4KB
byte[] buffer = new byte[tamanho];
clientSocket.close();
}
} [/code]