Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Unable to receive a simple string via TCP #2640

Closed
sercasyr opened this issue May 24, 2015 · 10 comments
Closed

Unable to receive a simple string via TCP #2640

sercasyr opened this issue May 24, 2015 · 10 comments

Comments

@sercasyr
Copy link

Hi,

I am trying to send a simple string via TCP from an external application to OpenHAB, using my LAN.
OpenHAB will act as the server, and my application, as the client.

The openhab.cfg is using the default values, and the binding seems correctly initialized, because it shows a message saying that it will receive values from 192.168.1.:

The item is bound with:

String sValue {tcp="<[192.168.1.::'REGEX((.*))']"}

But everytime I send a TCP packet, this is what I get in the log:

2015-05-24 11:07:20.864 [INFO ] [t.AbstractSocketChannelBinding] - Received connection request from /192.168.1.11:56343
2015-05-24 11:07:20.865 [INFO ] [t.AbstractSocketChannelBinding] - Disconnecting the unallowed remote end /192.168.1.11:56343

I have tried with Putty, and with a C# .NET application. I always get the "Disconnecting the unallowed remote end" message.

I have also tried from several computers. I have even tried to send the TCP packet from the same computer hosting OpenHAB. I have also tried with the 127.0.0.1 address, but neither of these tests worked...

I have read similar posts with similar unsolved issues. I don't know if I am doing something wrong or maybe the binding has issues working as a server.

My system is a Windows 8.1.

Can anyone help or should I give up?

@udo1toni
Copy link
Contributor

I think your binding definition is incomplete. If openHAB should act as a 'server' this does not mean, that multiple clients could connect to one item. So you must define complete IP-Adresses and also port. So the definition should be like String sValue {tcp="<[192.168.1.11:56343:'REGEX((.*))']"}
Secondly, maybe you have to allow incoming packets for openHAB in the Windows firewall.

@sercasyr
Copy link
Author

Hi,

I have also tried with an specific port and address, but it does not work either.
Besides, it's a little strange to only allow a connection from an specific port and address. To limit the client address could make sense, but not the client port, that's very very strange. Usually, the specific port is on the server side.

And... the openhab.cfg says that you can allow masks (*) in the binding configuration.

In any case, I think that's not the (only) problem here, because I've tried what you suggest and it didn't work.

The windows Firewall and the antivirus were also disabled...
Any ideas??

@kgoderis
Copy link
Contributor

Limiting the remote end port number is rather a way to secure the OH runtime, e.g. under normal conditions, or at least very often, remote devices or protocols emit data, or start connections, from well known or documented port numbers. Therefore, in order to prevent abuses, the port number can be defined. If you can not control the port number the remote client would use, then a wildcard should work. As to why it not taking the * wildcard for the inbound TCP connection, I can not tell right now - I has been a very long time since I revisited the source code. Can you enable DEBUGging output for the TCP binding and feed me what it is reporting?

Regards
K

On 25 May 2015, at 18:19, sercasyr notifications@github.com wrote:

Hi,

I have also tried with an specific port and address, but it does not work either.
Besides, it's a little strange to only allow a connection from an specific port and address. To limit the client address could make sense, but not the client port, that's very very strange. Usually, the specific port is on the server side.

And... the openhab.cfg says that you can allow masks (*) in the binding configuration.

In any case, I think that's not the (only) problem here, because I've tried what you suggest and it didn't work.

The windows Firewall and the antivirus were also disabled...
Any ideas??


Reply to this email directly or view it on GitHub #2640 (comment).

@sercasyr
Copy link
Author

Hi,

I couldn't find anything meaningful in the logs when it failed.
However, it looks like I had two problems:

-first, the binding does allow the * for the port (that makes sense) but it doesn't for the IP (so you can use 192.168.1.10:* but not 192.168.1.* : *).

-second, it seems that the regular expression failed with the strings I was sending.

Where can I find a good explanation of the syntax that REGEX() accepts??

@kgoderis
Copy link
Contributor

The binding should work with * in either port number or ip address

On the Regex, it uses the Transformation Service, like many other bindings. It does not accept any regular expression string, as you might expect, because of some assumptions made in the source code. This is a limitation of the REGEX, not the binding itself. Best thing to do is to go through the code execution with a debugger and see what happens

I am still interested in the DEBUG-level logs as that might indicate what is going on. Can you share the openhab.cfg configuration parameters you have used?

Tx
K

On 27 May 2015, at 09:41, sercasyr notifications@github.com wrote:

Hi,

I couldn't find anything meaningful in the logs when it failed.
However, it looks like I had two problems:

-first, the binding does allow the * for the port (that makes sense) but it doesn't for the IP (so you can use 192.168.1.10:* but not 192.168.1.:).

-second, it seems that the regular expression failed with the strings I was sending.

Where can I find a good explanation of the syntax that REGEX() accepts??


Reply to this email directly or view it on GitHub #2640 (comment).

@sercasyr
Copy link
Author

I will try again with 192.168.1.* : * as soon as I am able, because I can't do it now.
The problem is that my debug log is huge. Maybe I missed something.

This is the openhab.cfg config (I've changed the "#" for "/#" to avoid GitHub markdown) :

/# TCP - UDP Binding #

/# Port to listen for incoming connections
tcp:port=25001

/# Cron-like string to reconnect remote ends, e.g for unstable connection or remote ends
tcp:reconnectcron=0 0 0 * * ?

/# Interval between reconnection attempts when recovering from a communication error,
/# in seconds
tcp:retryinterval=5

/# Queue data whilst recovering from a connection problem (TCP only)
tcp:queue=true

/# Maximum buffer size whilst reading incoming data
tcp:buffersize=1024

/# Share connections within the Item binding configurations
tcp:itemsharedconnections=true

/# Share connections between Item binding configurations
tcp:bindingsharedconnections=true

/# Share connections between inbound and outbound connections
tcp:directionssharedconnections=false

/# Allow masks in ip:port addressing, e.g. 192.168.0.1:* etc
tcp:addressmask=true

/# Pre-amble that will be put in front of data being sent
tcp:preamble=

/# Post-amble that will be appended to data being sent
tcp:postamble=\r\n

/# Perform all write/read (send/receive) operations in a blocking mode, e.g. the binding
/# will wait for a reply from the remote end after data has been sent
tcp:blocking=false

/# timeout, in milliseconds, to wait for a reply when initiating a blocking write/read
/# operation
tcp:timeout=3000

/# Update the status of Items using the response received from the remote end (if the
/# remote end sends replies to commands)
tcp:updatewithresponse=true

/# Timeout - or 'refresh interval', in milliseconds, of the worker thread
tcp:refreshinterval=250

/# Timeout, in milliseconds, to wait when "Selecting" IO channels ready for communication
tcp:selecttimeout=1000

/# Used character set
tcp:charset=ASCII

@kgoderis
Copy link
Contributor

Could you modify the log_back.xml so that you have DEBUG logging enabled on the TCP binding?

Also note, that "192.168.1.” is not a valid mask. it is either an IP address in full, or “”. Nothing “in between”

K

On 27 May 2015, at 11:35, sercasyr notifications@github.com wrote:

I will try again with 192.168.1.* : * as soon as I am able, because I can't do it now.
The problem is that my debug log is huge. Maybe I missed something.

This is the openhab.cfg config:

TCP - UDP Binding

Port to listen for incoming connections

tcp:port=25001

Cron-like string to reconnect remote ends, e.g for unstable connection or remote ends

tcp:reconnectcron=0 0 0 * * ?

Interval between reconnection attempts when recovering from a communication error,

in seconds

tcp:retryinterval=5

Queue data whilst recovering from a connection problem (TCP only)

tcp:queue=true

Maximum buffer size whilst reading incoming data

tcp:buffersize=1024

Share connections within the Item binding configurations

tcp:itemsharedconnections=true

Share connections between Item binding configurations

tcp:bindingsharedconnections=true

Share connections between inbound and outbound connections

tcp:directionssharedconnections=false

Allow masks in ip:port addressing, e.g. 192.168.0.1:* etc

tcp:addressmask=true

Pre-amble that will be put in front of data being sent

tcp:preamble=

Post-amble that will be appended to data being sent

tcp:postamble=\r\n

Perform all write/read (send/receive) operations in a blocking mode, e.g. the binding

will wait for a reply from the remote end after data has been sent

tcp:blocking=false

timeout, in milliseconds, to wait for a reply when initiating a blocking write/read

operation

tcp:timeout=3000

Update the status of Items using the response received from the remote end (if the

remote end sends replies to commands)

tcp:updatewithresponse=true

Timeout - or 'refresh interval', in milliseconds, of the worker thread

tcp:refreshinterval=250

Timeout, in milliseconds, to wait when "Selecting" IO channels ready for communication

tcp:selecttimeout=1000

Used character set

tcp:charset=ASCII


Reply to this email directly or view it on GitHub #2640 (comment).

@sercasyr
Copy link
Author

It is 192.168.1.* : *
I think GitHub view did not showed it correctly, but it is correctly set in OpenHAB

@kgoderis
Copy link
Contributor

It should be 191.168.1.1:* or *:1234

@sercasyr
Copy link
Author

Ok.
Thus, that's the reason why it didn't work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants