Re: Prevent hibernate/standby/sleep
It will happen with either my script or J.M.'s as it is caused by the TCP session being held up. NETSTAT (which we both use in much the same manner) reports it as established, even though the remote device has long since been turned off. My reading on the web is that if a TCP session - effectively the link between your TV and the Serviio server - is not explicitly closed properly (eg. maybe if the TV is turned off, while still watching a stream) then it stays as established until the server works out it is no longer active. Some stuff on the web suggests there is a half an hour inactivity timer, but it doesn't seem to kick in for me (and your post confirms). I have had cases where it never seems to drop off, but I also have had cases where it does work it out (usually within 15 minutes). Maybe any TCP experts in the forum can shed some light...
The difference between my script and JM's is that
- I have used ports now rather than specific IP addresses to search for active TCP sessions. This is optional (an earlier script used IP addresses), but I think it makes it more robust (you don't have to worry about changing IP addresses, setting static IP's, or adding new devices. You also needed worry if your device, say an iPad, establishes a connection to the server for other, non-Serviio reasons). I also think it will be easier for most users as they don't have to change the script to match their individual IP addresses; and
- On detecting an active session on port 8895, I don't change power scheme profiles as JM did. I call a Windows API command to tell the PC not to go into full sleep, but rather enter a "half sleep" mode which still enables Serviio to run (technically this is called the AWAY MODE state - it is a mode specifically recommended for media streaming). The advantage is that you don't need to set up special power schemes. Once the session is closed, I then call the same command, but this time to tell it revert back to normal sleep mode.
The problem of the session remaining established is on my to-do list to work thru, but at the moment isn't a big concern (and I can't think of what the answer might be at this stage - maybe to find a WIN API commend to better test whether the session is active). This issue for me isn't a big deal - it means the server occasionally (when the session isn't closed) goes into "half-sleep" mode when sleeping (rather than normal "full sleep") - which for me is preferable than the alternatives (no sleep at all, falls asleep during a movie, or coffee.exe which sleeps as soon as you pause the movie). I have got rid of coffee.exe on my PC and am using this exclusively now.
ps. All cudo's and thanks to J.M. for this. I have simply suggested a few iterations on his/her scheme, but it was the work done in coming up with the approach that deserves the credit!