TCP binding cuts off received data

Hi there,

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

String OWinput { tcp=">[192.168.0.120:5000:default]"}

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

1_EVT|11:21:50
1_OWD1|2500
1_OWD2_1|2415
1_OWD2_2|498
1_OWD2_3|186
1_OWD2_4|0
1_OWD3|99999
---> 2 seconds pause
1_EVT|11:22:00
1_OWD1|2500
1_OWD2_1|2410
1_OWD2_2|498
1_OWD2_3|187
1_OWD2_4|0
1_OWD3|99999

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
1_OWD1|2562
 to 1_OWD2_1|2407
1_OWD2_2|498
1_OWD2_3|182
1_OWD2_4|0
1_OWD3|99999

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"
when
    Item OWinput changed
then
    ...

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 /192.168.0.120:5000 is not reconnecting.
I have to restart OpenHAB for the connection to be reestablished.