471,350 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Reconnection to Telnet after network failure

Hello,

I am new to python. I have been trying to connect to telnet and feed some data from a server. Its working properly. I used the connectionObj.read_until() method to read the data from the server and made the connection as


self.conn = telnetlib.Telnet(so.telnetHost, so.telnetPort)



thats too fine.

But in case of any network failure it throws an error as follows,

Error (10054, 'Connection reset by peer')

and this error occurred on reading the line

self.conn.read_until(delimiter).

How can I overcome this error or how can I reconnect to the server when recovering the network connection?

More than handling the exception by showing some custom messages, I want to reconnect to the telnet service. Actually the problem occurs in case of network failure where the exception is unavoidable and if system regain the connection then how can I check the connection and reconnect to the telnet to continue feeding the data from the telnet server without restarting the service or without any interaction from me?

Any help would be appreciated.

Thanks & Regards,
Sreejith
Oct 11 '07 #1
1 3000
bartonc
6,596 Expert 4TB
Typically we wrap things that may fail in a try block. That way you may handle the error gracefully and continue processing:
Expand|Select|Wrap|Line Numbers
  1. try:
  2.     self.conn.read_until(delimiter)
  3. except TelnetError:  # if there is such a thing. The error type is printed in the message
  4.     # Handle the error here
Oct 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by DCK | last post: by
6 posts views Thread by Donnal Walter | last post: by
5 posts views Thread by Greg Martz | last post: by
2 posts views Thread by b00x | last post: by
3 posts views Thread by jtagpgmr | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.