Python, recreate the socket and connect automatically

I am writing an IRC bot in Python.

Source: http://pastebin.com/gBrzMFmA (sorry for pastebin, I don’t know how to efficiently / correctly use the codething tag here)

When the irc jack dies, can I still find that it is dead and then automatically reconnects?

I had been searching Google for some time and found that I would need to create a new socket. I tried and added things like catching socket.error while True: but it seems to just freeze and not plug in correctly again.

Thanks for the help in advance.

+5
source share
1 answer

Answered here: Python: check if IRC connection is lost (PING PONG?)

, , , soley : fooobar.com/questions/1152173/...

, -

def connect():
    global irc
    irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    irc.connect((server, port))
    #and nick, pass, and join stuffs
connect()
while True:
    data = irc.recv(4096)
    if len(data) == 0:
        print "Disconnected!"
        connect()
+5

All Articles