Skip to content
This repository has been archived by the owner on Jul 12, 2021. It is now read-only.

Commit

Permalink
ping the server to know if we are disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasV committed Aug 21, 2014
1 parent 3366552 commit f101bee
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/irc.py
Expand Up @@ -78,7 +78,7 @@ def run(self):
try:
s = socket.socket()
s.connect(('irc.freenode.net', 6667))
s.settimeout(0.3)
s.settimeout(1)
except:
s.close()
print_log("IRC: reconnect in 10 s")
Expand All @@ -94,23 +94,26 @@ def run(self):
if self.password:
s.send('NICKSERV IDENTIFY ' + self.password + '\n')
s.send('JOIN #electrum\n')
t = 0

t = time.time()
while not self.processor.shared.stopped():
try:
data = s.recv(2048)
except socket.timeout, e:
if time.time() - t > 120:
out_msg.append('PING')
if out_msg:
m = out_msg.pop(0)
#print_log("-->", m)
s.send(m + '\n')
continue
except:
print_log( "irc: socket error" )
print_log("irc: socket error")
time.sleep(1)
break

self.message += data
t = time.time()

while self.message.find('\n') != -1:
pos = self.message.find('\n')
Expand Down

0 comments on commit f101bee

Please sign in to comment.