I am using this to control a device on my LAN, but I had to make one modification to get it to work. The device requires SSL, even though it can't possibly return a valid certificate. There didn't appear to be any way around this with the IE-based WebSocket, but the following line added to
connect() allows this script to work:
Code: Select all
DllCall('Winhttp\WinHttpSetOption', 'ptr', hRequest, 'uint', 31, 'uint*', 0x3300, 'uint', 4, 'int')
This ignores certificate errors, so shouldn't be default behaviour. It would be helpful to make this an option somehow.
I also reduced the timeout on connection, but the script still seemed to take 4-5 seconds minimum. For that I tried a few things:
Code: Select all
DllCall('Winhttp\WinHttpSetTimeouts', 'ptr', hSession, 'int', 500, 'int', 500, 'int', 500, 'int', 500, 'int')
DllCall('Winhttp\WinHttpSetTimeouts', 'ptr', hRequest, 'int', 500, 'int', 500, 'int', 500, 'int', 500, 'int')
DllCall('Winhttp\WinHttpSetOption', 'ptr', hRequest, 'uint', 3, 'uint*', 500, 'uint', 4, 'int')
They all had the same result; reducing the timeout from around 60 seconds to around 5.
Perhaps the script could allow for these options via properties of the second parameter, or provide a callback to modify the request prior to sending.
I intended to use the timeout to detect that the device is turned off, so I can toggle it on/off by combining WebSocket with wake on LAN.
Thank you for the useful script!