Java socket not printing what it should

Asked

Viewed 69 times

2

Server:

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
            String s = inFromClient.readLine();
            System.out.println("> "+s);

This simple code is returning the following output:

Problema

How to make it not show these squares in the output, but show the content the message (fifth line of the console)?

Complete code:

package com.estilosoft.servidor;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; 
import java.net.ServerSocket;
import java.net.Socket;

public class Servidor {

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    String clientSentence;
    String capitalized;
    ServerSocket socket = null;

    try {

        // Cria um SocketServer (Socket característico de um servidor)
        socket = new ServerSocket(6831);
        System.out.println("abriu");

        while(true) {    
            Socket connectionSocket = socket.accept();
            System.out.println("Con "+ connectionSocket.getInetAddress().getHostAddress());

            BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
            System.out.println("Iniciou");
            String s = inFromClient.readLine();
            System.out.println("Acabou");
            System.out.println("> "+s);


        } 

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        socket.close();
        System.out.println("fechou");
    }  
}


}
  • What is being sent to the server?

  • So @bfavaretto I’m not sure what’s being sent, so it looks like it’s not a plain text but a file or something. (I don’t have much customer information).

  • Can you post the code instead of posting an image? We need to know what the customer is sending.

  • @Since I updated the publication with the server class, I still don’t have much implemented, besides being initial I don’t know for sure what is being sent to the server, this is my mission, to find out what is being sent. kkk (I made a Sniffer on the network and it seems to be an xml file, not sure)

  • 1

    Usually (I say because its use seems unusual), the server and client need to have some kind of contract: either the server knows what it expects to receive, or the client warns what it will send. Without knowing any of this, everything is bytes, and the same bytes can be interpreted in different ways. You will need lots of tests and inferences to find out what is being sent.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.