TCP binding cuts off received data

Hi there,

I’m trying to receive data from a TCP server:

String OWinput { tcp=">[]"}

The server accepts the connection and sends data every 2 seconds like this:

---> 2 seconds pause

The item is updated and I can parse the input in a rule:

2019-03-02 22:07:53.161 [vent.ItemStateChangedEvent] - OWinput changed from 1_EVT|22:07:53
 to 1_OWD2_1|2407

From time to time the binding cuts the received data somewhere in the middle which makes parsing difficult / impossible. Sometimes not even on a newline.

How can I make sure that the binding reads all the data that comes in on a 2 second interval?

I tried to set refreshinterval in the binding config to 1000 or even 2500 but this had no effect on the place where binding cut the data.

Any ideas?

Do you ever send commands to your Item?

No, I only have a rule that listens for updates …

rule "Read OWinput values"
    Item OWinput changed

How does the binding know when to update the item?

Well, you’ve configured your Item for outbound TCP (with >).
The usual way to use that would be to to send a command from OH and get a response from remote server.
The way I read your description, your server is just sending data every couple of seconds unprompted.
I was just worried you might send a command in the middle of a receive packet.

I don’t suppose being an output matters if you are not sending commands, the binding listens for data anyway. It’s just about who is client and who is server.

I guess when the packet is complete. I don’t know if it deals with fragmented TCP properly.

From docs

The TCP part of the binding has a built-in mechanism to keep connections to remote hosts alive, and will reset connections at regular intervals to overcome the limitation of “stalled” connections or remote hosts.

Maybe connection resets while you have incoming data

Thanks, @rossko57!

After playing around with different settings of the binding I managed to configure the server differently. It now sends all the data in a single line and only one CR at the end. Now the binding seems not cut the data anymore.

However, when I unplug/plug the network cable of the server (controller) the connection is never reestablished. There is absolutely no indication in the log that the connection is broken (changed to DEBUG). It looks like the binding waits forever for data to come.

For testing I configured “reconnectcron” to one minute. Even after plugging in again all I got was:
2019-03-04 22:03:00.002 [WARN ] [ing.tcp.AbstractSocketChannelBinding] - Channel for / is not reconnecting.
I have to restart OpenHAB for the connection to be reestablished.