1
I have my Client and Server classes. I want to send String to the server. I have tried several methods but error or it sends an empty string to the server. Someone can give me a light of what I am doing wrong?
public class Cliente {
    ArrayList<Integer> armazenar = new ArrayList<>();
    public static void main(String[] args)
            throws IOException {
        Socket cliente = new Socket("127.0.0.1", 12345);
        System.out.println("O cliente se conectou ao servidor!");
        Cliente c = new Cliente();
        // LER ARQUIVO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        System.out.printf("Lendo arquivo impar.txt\n");
        String nome = "/home/teste/impar.txt";
        System.out.printf("\nConteúdo do arquivo de texto:");
        try {
            FileReader arq = new FileReader(nome);
            BufferedReader lerArq = new BufferedReader(arq);
            String linha = "";
            // a variável "linha" recebe o valor "null" quando o processo
            // de repetição atingir o final do arquivo texto
            while (linha != null) {
                System.out.printf("%s\n", linha);
                linha = lerArq.readLine(); // lê da primeira até a última linha
                try {
                    c.armazenar.add(Integer.parseInt(linha));
                } catch (NumberFormatException e) {
                    e.getMessage();
                }
            }
            String armazenarString = c.armazenar.toString();
            System.out.println("\nSalvando valores do arquivo impar.txt na variavel armazenarString: " + armazenarString);
            System.out.println("Enviando os dados para o servidor!");
            arq.close();
            cliente.close();
        } catch (IOException e) {
            e.getMessage();
        }
    }
}
.
public class Servidor {
    public static void main(String args[]) throws IOException {
        ServerSocket servidor = new ServerSocket(12345);
        System.out.println("Porta 12345 aberta!");
        Socket cliente = servidor.accept();
        System.out.println("Nova conexão com o cliente " +
                cliente.getInetAddress().getHostAddress()
        );
        servidor.close();
        cliente.close();
    }
}
I don’t see you sending data to the server. Anyway, use the Socket.getOutputStream() method and work with sockets in a file-like way to send messages
– Felipe