February 11th, 2005, 07:37 PM
Is this loop sending too much information by any chance? While Battle.net is connected and so is the IRC, could the IRC be interferring with the data that the socket connected to battle.net is trying to receive? Because I've noticed that Battle.net stops receiving data about 30 seconds after IRC has been connected.
IRCs.readbuffer = IRCs.readbuffer + irc.recv(1024)
tmp = string.split(IRCs.readbuffer, '\n')
IRCs.readbuffer = tmp.pop()
for line in tmp:
line = string.rstrip(line)
line = string.split(line)
if line == 'PING':
irc.send('PONG %s\r\n' % line)
February 12th, 2005, 03:26 PM
interleaving communication with two sockets like this is not a good idea. If the sockets are in blocking mode (the default) then a call to recv will wait until it has received 1024 bytes, the socket times out (which may be never if the timout is set to None, the default), or the connection is closed.
So if the IRC connection is not sending any data then the call to irc.recv will never return, and the program will hang.
There are a couple of ways round this problem. The first is to have a multi-threaded program with separate threads for communicating with the two different sockets, and a queue for passing messages between them. The second is to use an asynchronous framework such as the asyncore & asynchat libraries that come with Python or the twisted framework that builds on those libraries. I believe that twisted already comes with an IRC module, so may have done half your work for you.
I suggest you have a good look at the asyncore/chat libraries and rethink your whole approach, since to be honest the way you are currently doing it is doomed to failure.
Dave - The Developers' Coach