jquast / telnetlib3

Python Telnet server and client Protocol library using asyncio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle Server Disconnects

iwoloschin opened this issue Β· comments

First, this library is great πŸ˜„!

I've got a few serial devices that work quite well with it, but I've got one device that is a bit flakey. Sometimes I get bad values back (I suspect this can be solved with some asyncio.sleep(1) calls to ensure commands aren't colliding), other times it just hard disconnects. I'd like to abstract away all of these issues by automatically opening a new telnet connection but I can't seem to figure out what the right way to do that is.

It appears that I can catch a RuntimeError to find a broken StreamWriter, but what's the proper way to close the broken one and open a new one? Ideally I'd like this to happen transparently so that the user doesn't even realize a new connection has been opened. This case is a bit simpler as the device's state is held independently of the telnet connection, so no initialization code is required, just reopening the connection.

I do not have an error stack trace handy at the moment, I'll make sure to copy it next time I see an error.

Sorry for the late reply... ]the StreamReader should return an empty string, '' on disconnect, the traditional way of signaling EOF. Does that work for your case?

I've completely forgotten where I was having this problem...so yes? :) I'll go ahead and close this, the question is answered and if I run into whatever problem it was, I have something to try.

Thanks!