January 31st, 2005, 07:46 PM
Ok, I'm very confused with my Queue. Before I shwo you my code, here is what I'm trying to get it to do. When data is added to the Queue, it will attempt to Send the data to battle.net, however, you can only send (about) 4 messages at the same time before getting ipbanned from the server. What I want to do is if it's the first data that gets added, Send it right away, same with the second third and fourth, if it sends atleats 4 at the same time, wait 5 seconds before sending any more. So it will know how many messages have been sent before it sends one, and it will determine how long to wait to send the data.
Here is the code I've come up with so far.
Now, my main problem is that I don't know how to determine how many messages have already been sent, if i use a list, how will i know when 5 seconds is up if its sent 4 messages at about the same time? Can anyone help?
if len(q) == 0:
if q >= 224:
# Data too large
if len(q) == 1:
if qt >= time.strftime("%S") + 4:
elif qt >= time.strftime("%S") + 4:
added = added + 1
February 1st, 2005, 09:08 PM
How about some pseudo code like this...
Set message count variable to zero
Set "previous" time variable to zero.
On posting a message
Note the time
Is the message count less than 5
increment message count and send immediatley
set "previous" time to current time.
if time difference less then 5 then
pause 5-diiference seconds
set count to zero
set previous time to current time
February 2nd, 2005, 05:18 PM
Thanks a lot for the code. It really cleared things up for me. I'm a little confused, but I think I can finish it this time on my own. Thanks again.
February 2nd, 2005, 06:26 PM
Just a few notes on the current code: you appear to be using the same expression for your last if and elif statements, in this case you don't need the elif at all . You also seem to be adding 4 to the string returned by the strftime() function, which has me a little confused.
Originally Posted by †Yegg†
Anyway, I've made a few changes to the flow of the program that you might be interested in.
Note: this is untested and may not work like you want it to. I've also made the section I mentioned above bold to make it easier to see.
if len(q) > 0:
if q >= 224:
if len(q) == 1 and qt >= time.strftime("%S") + 4:
Hope this helps,
February 2nd, 2005, 08:22 PM
Ya, I know, my current code now is much better. I'm just trying to get by a referrenced before assignment problem.