From 022513ee85878f2f9cf2fd27fa3d79d251197c5a Mon Sep 17 00:00:00 2001 From: Andrew Fiddian-Green Date: Tue, 13 Apr 2021 15:00:10 +0100 Subject: [PATCH] [neohub] eliminate once in a blue moon fin-ack fin-ack issues Signed-off-by: Andrew Fiddian-Green --- .../binding/neohub/internal/NeoHubSocket.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubSocket.java b/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubSocket.java index 5a6daf5cad980..8801ba7945935 100644 --- a/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubSocket.java +++ b/bundles/org.openhab.binding.neohub/src/main/java/org/openhab/binding/neohub/internal/NeoHubSocket.java @@ -64,7 +64,7 @@ public NeoHubSocket(final String hostname, final int portNumber, final int timeo * @param requestJson the message to be sent to the NeoHub * @return responseJson received from NeoHub * @throws NeoHubException, IOException - * + * */ public String sendMessage(final String requestJson) throws IOException, NeoHubException { IOException caughtException = null; @@ -84,15 +84,20 @@ public String sendMessage(final String requestJson) throws IOException, NeoHubEx writer.write(requestJson); writer.write(0); // NULL terminate the command string writer.flush(); + socket.shutdownOutput(); if (logger.isTraceEnabled()) { logger.trace("sent {} characters..", requestJson.length()); } int inChar; - // NULL termination, end of stream (-1), or newline - while (((inChar = reader.read()) > 0) && (inChar != '\n')) { - builder.append((char) inChar); + boolean done = false; + // read until end of stream + while ((inChar = reader.read()) != -1) { + // a JSON block is terminated by a newline or NULL + if (!(done |= (inChar == '\n') || (inChar == 0))) { + builder.append((char) inChar); + } } } } catch (IOException e) {