When I save a sentence in a String, it only saves me the first word.
How can I solve this?
Customer code:
public static void main(String[] args) {
String fraseResult;
try(ServerSocket socketServidor = new ServerSocket(PORT)){
while(true) {
System.out.println("Esperant connexions....");
try (Socket connexio = socketServidor.accept();
DataInputStream input = new DataInputStream(connexio.getInputStream());
DataOutputStream output = new DataOutputStream(connexio.getOutputStream());) {
System.out.println("Conexxio acepted...");
String fraseRebut = input.readUTF();
System.out.println("Missatge rebut:" + fraseRebut);
output.writeUTF(fraseRebut + "des del servidor");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Server code:
public static void main(String[] args) {
Scanner lec =new Scanner(System.in);
int port = 8080;
try(Socket socket = new Socket(HOST,PORT);
DataInputStream input = new DataInputStream(socket.getInputStream());
DataOutputStream output = new DataOutputStream(socket.getOutputStream());){
String frase=lec.next();
String fraseRebut=frase.toUpperCase();
output.writeUTF(fraseRebut);
fraseRebut = input.readUTF();
System.out.println("Missatge rebut:" + fraseRebut);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
}
}