Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client connection gets stuck forever #50

Open
seizu opened this issue Nov 17, 2023 · 1 comment
Open

Client connection gets stuck forever #50

seizu opened this issue Nov 17, 2023 · 1 comment

Comments

@seizu
Copy link

seizu commented Nov 17, 2023

If you disconnect the LG TV from the power supply and then switch it on again, there is a small time window during the boot-up sequence where a TCP connection can be established. Approx. 7 seconds. If the LGTV2 client establishes the connection to the LG TV exactly during this time, the client hangs forever and blocks any further processes.

Do you have an idea or a workaround to prevent this?

You can test it by pinging the TV during boot-up. If the server responds, try to establish a connection with your LGTV2 client.
Important: Before disconnecting the LG TV from the power supply, switch off the TV with the remote control and wait 10 minutes until the pixel cleaning process has been completed. This process runs in the background after switching off the TV.

(Windows ping)
c:\>ping 192.168.1.70 -t

Pinging 192.168.1.70 with 32 bytes of data:
Reply from 192.168.1.10: Destination host unreachable. <--- Boot up LGTV
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.70: bytes=32 time=5ms TTL=63 <--- Connect here
Reply from 192.168.1.70: bytes=32 time=4ms TTL=63
Reply from 192.168.1.70: bytes=32 time=5ms TTL=63
Reply from 192.168.1.70: bytes=32 time=5ms TTL=63
Reply from 192.168.1.70: bytes=32 time=5ms TTL=63
Reply from 192.168.1.70: bytes=32 time=5ms TTL=63
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.10: Destination host unreachable.
Reply from 192.168.1.10: Destination host unreachable.

@seizu
Copy link
Author

seizu commented Nov 20, 2023

After further research, I found out that it is more likely to be a websocket related issue which is described here.
Websocket-Node No timeout

A fix for LGTV2 might look like this...

In the constructor, pass a user-defined parameter for the connection timeout, e.g. conTimeout

var lgtv2 = require("lgtv2");
var lgtv =  new lgtv2({url: `${wsurl}`, keyFile : 'keyFile', reconnect: 5000, wsconfig:{'conTimeout':5000, ... });
...

WebSocketClient.js (line 254)

    var req = this._req = (this.secure ? https : http).request(requestOptions);    
+    req.on('socket', function (socket) {
+       socket.setTimeout(self.config['conTimeout']);  
+       socket.on('timeout', function() {
+           req.destroy();
+      });
+   });

WebSocketClient.js (line 87) extend the config

+      conTimeout: 5000,

Edited: The previous solution did not work! I had to patch the WebSocketClient.js after all :(

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

No branches or pull requests

1 participant