GoogleCodeArchive / msnp-sharp

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

Why I can't receive the message sometimes? #324

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?
receive message stably

What version of the product are you using? (MSNPSharp, OS, Mono etc.)
MSNPSharp 5.0.5 (recompiled on .net 4.0)
.net 4.0
Visual Studio 2010

Is your code clone from GIT or download from our download page?
download from our download page

Please provide any additional information below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace msn
{
    using MSNPSharp;
    using System.Threading;
    public class MSNTool : IDisposable
    {
        Messenger messenger;
        public MSNTool(string id, string pwd)
        {
            messenger = new Messenger();

            messenger.ConnectingException += (a, b) =>
                {
                    throw b.Exception;
                };

            messenger.Nameserver.ExceptionOccurred += (a, b) =>
                {
                    throw b.Exception;
                };
            messenger.Nameserver.ServerErrorReceived += (a, b) =>
                {
                    throw new ApplicationException(b.Description);
                };
            messenger.Nameserver.AuthenticationError += (a, b) =>
            {
                throw b.Exception;
            };

            messenger.Credentials = new Credentials(id, pwd);

            //var gM = new AutoResetEvent(false);
            bool tmpResume = false;

            var hander=new EventHandler<EventArgs>((s, ar) =>
            {
                //Console.WriteLine("Sign in.");
                //gM.Set();
                tmpResume = true;
            });

            //messenger.ConnectionEstablished += (a, b) =>
            //    {
            //        Console.WriteLine("Connected");
            //    };

            messenger.Nameserver.SignedIn += hander;
            messenger.Nameserver.AutoSynchronize = true;

            messenger.Connect();
            //gM.WaitOne();
            do
            {
                if (tmpResume)
                    break;
                Thread.Sleep(1000);
            }
            while (true);
            messenger.Nameserver.SignedIn -= hander;

            //Console.WriteLine("ctor.");
        }

        Contact remoteContact = null;
        public string ToContact
        {
            get
            {
                if (remoteContact != null)
                    return remoteContact.Account;
                else
                    return null;
            }
            set
            {
                foreach (var t in messenger.ContactList.All)
                {
                    if (t.Account == value)
                    {
                        remoteContact = t;
                        break;
                    }
                }
            }
        }

        public void SendMsg(string msg)
        {
            TextMessage message = new TextMessage(msg);

            remoteContact.SendMessage(message);
        }

        public event EventHandler<EventArgs> SignedIn
        {
            add
            {
                messenger.Nameserver.SignedIn += value;
            }
            remove
            {
                messenger.Nameserver.SignedIn -= value;
            }
        }

        public event EventHandler<TextMessageArrivedEventArgs> TextMessageReceived
        {
            add
            {
                messenger.MessageManager.TextMessageReceived += value;
            }
            remove
            {
                messenger.MessageManager.TextMessageReceived -= value;
            }
        }

        public void Dispose()
        {
            if (messenger.Connected)
                messenger.Disconnect();
        }
    }
}

Main code:
        static void Main(string[] args)
        {
            try
            {

                using (var msn = new jks.msn.MSNTool("begtostudy@gmail.com", "****"))
                {
                    msn.ToContact = "begtostudy@hotmail.com";
                    msn.SendMsg("Finished");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

The receiver can't receive the message sometimes, but sometimes can.

Original issue reported on code.google.com by begtost...@gmail.com on 3 May 2012 at 4:05

GoogleCodeExporter commented 9 years ago
Would you please provide a trace log of the library when it can't receive 
messages?

Original comment by freezing...@gmail.com on 3 May 2012 at 11:51

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Please see log.txt

Original comment by begtost...@gmail.com on 4 May 2012 at 2:06

Attachments:

GoogleCodeExporter commented 9 years ago
Can you login with the official WLM and check if the same thing happens? It 
seems that you are not receiving anything from the server.

Original comment by freezing...@gmail.com on 5 May 2012 at 8:18

GoogleCodeExporter commented 9 years ago

Original comment by freezing...@gmail.com on 8 May 2012 at 4:31

GoogleCodeExporter commented 9 years ago
No problems in WLM and the example of the project.
Only for my program, others can't receive the message sometimes.

I want to transform the asynchronous to synchronous program for avoiding the 
main thread closed before the message is sent by MSNPSharp.

Original comment by nichola...@gmail.com on 10 May 2012 at 8:34

GoogleCodeExporter commented 9 years ago
Then this is not in our support scope...

Original comment by freezing...@gmail.com on 12 May 2012 at 5:34