GoogleCodeArchive / msnp-sharp

Automatically exported from code.google.com/p/msnp-sharp
0 stars 0 forks source link

How to end a conversation as soon as the message is sent to overcome session limitation #251

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I know this is not a defect. I just don't get the kind of place like forum to 
raise my question.

In my situation, the msn robot is broadcasting messages to its subscribers. The 
session limitation will be a problem. As my observation, the max concurrent 
session number is 8 to 11. So what I do is to end the the session after a 
message is sent and then send the next message. However, ending session will 
cause the message sent failed. I can unstand that.

I also try to set the converstion keep alive property to false but it still 
does not close session in a short period.

Thank you for your advice!

Original issue reported on code.google.com by shoujies...@gmail.com on 31 Jan 2011 at 6:25

GoogleCodeExporter commented 9 years ago
Which API are you using? Conversation or MessageManager?

Original comment by freezing...@gmail.com on 31 Jan 2011 at 7:12

GoogleCodeExporter commented 9 years ago
I am using MessageManager.

it reports RateLimiteExeeded error 

Original comment by shoujies...@gmail.com on 31 Jan 2011 at 7:17

GoogleCodeExporter commented 9 years ago
Something I find interesting:

at first, the robot doesn't have any contact and then start to accept 
invitation from other contacts.
eventually, there are 18 contacts on the list. when a contact is added, it is 
also added into the message loop. The message is sent in every 10 seconds.
Everything here is fine.

after I restart the robot, it login and start to send message to its 18 
contacts and the RateLimiteExeeded error thrown out. 8 or maybe 11 contacts 
receive the message while others don't.

The frequency to send messge in 2 cases is the same.

Original comment by shoujies...@gmail.com on 31 Jan 2011 at 8:59

GoogleCodeExporter commented 9 years ago
can you attach the trace log output from MSNPSharp?

Original comment by freezing...@gmail.com on 31 Jan 2011 at 9:53

GoogleCodeExporter commented 9 years ago
Try to use MessageManager.EndConversation(ConversationId) to force a 
conversation exit.

Original comment by freezing...@gmail.com on 31 Jan 2011 at 10:04

GoogleCodeExporter commented 9 years ago
Thanks again!
I use MessageManager.EndConversation to close a conversation. Here is the trace 
log. 

Original comment by shoujies...@gmail.com on 31 Jan 2011 at 1:56

Attachments:

GoogleCodeExporter commented 9 years ago
All message you sent is UUM offline message, before sending your message out, 
please check whether the contact is online, or listen to 
NSMessageHandler.ContactOnline event.

Original comment by freezing...@gmail.com on 31 Jan 2011 at 8:48

GoogleCodeExporter commented 9 years ago
thank you for reminding.
I tested it again. This time, the messages were sent to online contact.
Here are 2 logs:
trace-end-conversation.log -- I use MessageManager.EndConversation to close a 
conversation
trace-not-end-conversation.log -- I don't explicitly close a conversation.

Original comment by shoujies...@gmail.com on 1 Feb 2011 at 2:01

Attachments:

GoogleCodeExporter commented 9 years ago
The problem is, you can't initial too many conversation in a short period. I 
guess you just a for(..){ sendmessage(..); } style code, this is going to flood 
Microsoft's server, so you get the error. Try to send message slower. BTW, 
please add timestamps to the log.

Original comment by freezing...@gmail.com on 4 Feb 2011 at 8:22

GoogleCodeExporter commented 9 years ago
Yes, what i do is
for (contact in contact list)
{
ConversationID converId = messenger.MessageManager.GetID(c);
                    converId = messenger.MessageManager.SendTextMessage(converId, new TextMessage(msg));
                    messenger.MessageManager.EndConversation(converId);
}
I thought using EndConversation method can help me work around session 
limitaion but it not.

I have added the timestamp to the log.

Original comment by shoujies...@gmail.com on 4 Feb 2011 at 4:04

Attachments:

GoogleCodeExporter commented 9 years ago
You need to know that all the calling are asynchronous, that means, when you 
call messenger.MessageManager.SendTextMessage(converId, new TextMessage(msg));
The conversation is actually not yet established. What the library do is 
putting your requests in the queue and waiting the conversation connected and 
all the negotiation done. The conversation will established a few seconds after 
you call MessageManager.SendTextMessage. However, you call EndConversation 
BEFORE it actually done with the negotiation. So nothing will happen (since the 
conversation is not yet created, nothing will be ended), you are still flooding 
Microsoft's server.

Original comment by freezing...@gmail.com on 4 Feb 2011 at 9:18

GoogleCodeExporter commented 9 years ago
The whole logic works like this: When you call MessageManager.SendTextMessage, 
you message was put into a queue, the method return immediately, and the 
library began to request a conversation from Microsoft MSN server. The request 
procedure will lasts for several seconds. Once a conversation was established, 
the library will pop the message from the queue and send it out. You CANNOT 
request too many conversation at a time (This is what you are doing now) or you 
will get a server error. 

Original comment by freezing...@gmail.com on 4 Feb 2011 at 9:23

GoogleCodeExporter commented 9 years ago

Original comment by freezing...@gmail.com on 4 Feb 2011 at 9:23

GoogleCodeExporter commented 9 years ago
Thanks for explaination. I think I will build a queue to hold the sessions.
Is there any way I can be notifed that a message has been sent? Otherwise, I 
have to wait for 5 seconds(for example) since the conversation is initiated so 
that I can invoke EndConversation() method successfully?

Original comment by shoujies...@gmail.com on 5 Feb 2011 at 7:02

GoogleCodeExporter commented 9 years ago
I am afraid that you need to use the old conversation API (The MessageManager 
is just a wrapper for the conversation API, you can take a look at how I 
implement it), which will leverage the conversation directly.

Original comment by freezing...@gmail.com on 5 Feb 2011 at 7:16

GoogleCodeExporter commented 9 years ago
BTW, if you have further question, please send me email: 
freezingsoft@hotmail.com.

Original comment by freezing...@gmail.com on 5 Feb 2011 at 7:17