help using sockets, and OOP?
exarkun at divmod.com
Sun Dec 5 21:17:31 CET 2004
On Mon, 06 Dec 2004 06:02:40 +1000, Dfenestr8 <chrisdewinn0spam at yahoo.com.au> wrote:
> I realise, that there's probably something intrinsic to OOP that I don't
> understand here. Or maybe it's something to do with sockets. I'm not sure.
> Basically, I'm trying to hack up an IRC bot, that joins two servers at
> once. I use two object instancs of the same class, both of which make
> connections using the socket module.
> Problem is, I can't seem to get both objects to connect to their
> constituent servers at the same time. I'm not sure whether it's that both
> objects can't instantiate at once, or whether only one can use the socket
> module at any one time.
> Here's my code:
> Can anybody see what it is I'm missing?
Your problem doesn't seem to have anything to do with "OOP" (whatever that is). Rather, you are trying to use two blocking sockets at once.
socket.connect() and socket.recv() are both "blocking" operations by default - they can take an arbitrary amount of time to return. Additionally, Botling.receiveData, one of your own functions, is also blocking: it will actually loop forever, never returning (until an exception blows it up). So execution of your program never even _gets_ to the "bert2 = ..." line. It's stuck running bert1.receiveData().
Handling concurrency can be quite tricky, but fortunately there are some tools to help you out. For starters, check out http://www.twistedmatrix.com/ - in particular, you may be interested in
More information about the Python-list