Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
peste89 #1
Member since May 2008 · 2 posts · Location: San Jose
Group memberships: Members
Show profile · Link to this post
Subject: Attempt to connected time out
Hi!!!

I am working with VS2005, Windows Mobile 6 and .Net compact framework and
using C:\Program Files\AG-Software\agsXMPP SDK\agsxmpp\bin\PPC_20\Debug\agsXMPP.dll.

I made a server and client program on Windows (not windows mobile) which were working fine.

Then I moved client program on Windows Mobile 6.
I got an error XmppSocketError(Attempt to connected time out) after XmppConnection.Open().

First, I suspected Windows Mobile 6 Emulator Configuration. But when I tried to connect with plain Socket API,
client program connected with Server. But Using XmppConnection.Open(), I always got Socket TimeOut Error.

Please help me.

Here is source code.
namespace PalmCasterSmart
{
     public partial class PalmMain : Form
     {
          delegate void setObjectCB(object obj);

          XmppConnection cClientConn;

          public PalmMain()
          {
               InitializeComponent();

               cClientConn = new XmppConnection();
               cClientConn.OnLogInSuccess += new XmppConnection.PnmpBasicHandler(this.OnLoginSuccess);
          }

          private void LoginButton_Click(object sender, EventArgs e)
          {

               if (LoginButton.Text == "Login")
               {
                    try
                    {
                         cClientConn.LogIn(UserID.Text, UserPassword.Text);
                    }
                    catch (NullReferenceException a)
                    {
                         Console.WriteLine(a.ToString());
                    }
               }
               else
               {
                    cClientConn.LogOut();
                    this.Text = "OffLine";
                    LoginButton.Text = "Login";
               }
          }

       private void OnLoginSuccess(object o)
        {
            if (this.InvokeRequired)
            {
                setObjectCB sCB = new setObjectCB(OnLoginSuccess);
                try
                {
                    this.Invoke(sCB, new object[] { o });
                }
                catch (NullReferenceException e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            else
            {
                this.Text = "OnLine (Server)";
                LoginButton.Text = "Logout";
            }
        }
     }
}

namespace PalmCasterSmart
{
    public class XmppConnection
    {
        public delegate void PnmpBasicHandler(object sender);
        public delegate void PnmpXmlMsgHandler(object sender, Message sMsg);

        public delegate void XnmpPresenceHandler(object sender, Presence pres);

        public event PnmpBasicHandler OnLogInSuccess;
        public event PnmpBasicHandler OnLogInFailure;
        public event PnmpXmlMsgHandler OnReceiveMsg;
        public event XnmpPresenceHandler OnPresenceMsg;

        protected XmppClientConnection mXMPPCon;

        public XmppConnection()
        {
            mXMPPCon = new XmppClientConnection();   
        }

        public virtual void LogIn(string sID, string sPwd)
        {
             if (mXMPPCon == null)
                 mXMPPCon = new XmppClientConnection();

             mXMPPCon.OnLogin += new ObjectHandler(OnXmppOnLogin);
             // Automatically Accept Subsccription
             mXMPPCon.OnPresence += new agsXMPP.protocol.client.PresenceHandler(OnXmppOnPresence);
             mXMPPCon.OnAuthError += new XmppElementHandler(OnXmppAuthError);
             mXMPPCon.OnRegisterError += new XmppElementHandler(OnXmppRegisterError);
             mXMPPCon.OnError += new ErrorHandler(OnXmppError);
             mXMPPCon.OnMessage += new MessageHandler(OnPnmpMsgHandler);
             mXMPPCon.OnSocketError += new ErrorHandler(OnXmppSocketError);
             mXMPPCon.OnClose += new ObjectHandler(OnXmppClose);
             mXMPPCon.OnXmppConnectionStateChanged += new XmppConnectionStateHandler(OnConStateChanged);
        

            GtalkLogIn(sID, sPwd);
        }

        public virtual void ReLogIn(string sID, string sPwd)
        {
            if (mXMPPCon != null)
                mXMPPCon.Close();
            mXMPPCon = new XmppClientConnection();

            mXMPPCon.OnLogin += new ObjectHandler(OnXmppOnLogin);
            mXMPPCon.OnPresence += new agsXMPP.protocol.client.PresenceHandler(OnXmppOnPresence);
            mXMPPCon.OnAuthError += new XmppElementHandler(OnXmppAuthError);
            mXMPPCon.OnRegisterError += new XmppElementHandler(OnXmppRegisterError);
            mXMPPCon.OnError += new ErrorHandler(OnXmppError);
            mXMPPCon.OnMessage += new MessageHandler(OnPnmpMsgHandler);
            mXMPPCon.OnSocketError += new ErrorHandler(OnXmppSocketError);
            mXMPPCon.OnClose += new ObjectHandler(OnXmppClose);
            mXMPPCon.OnXmppConnectionStateChanged += new XmppConnectionStateHandler(OnConStateChanged);
        

            GtalkLogIn(sID, sPwd);
        }

        public virtual void LogOut()
        {
            if (mXMPPCon != null)
            {
                mXMPPCon.Close();
                mXMPPCon.SocketDisconnect(); //
                mXMPPCon = null;
            }
        }

        protected void GtalkLogIn(string sID, string sPwd)
        {
            if (mXMPPCon != null)
            {
                // mXMPPCon.Server = "gmail.com";
                // mXMPPCon.ConnectServer = "talk.google.com";
                mXMPPCon.Server = "192.168.0.12";
                mXMPPCon.ConnectServer = "192.168.0.12";
                mXMPPCon.Username = sID;
                mXMPPCon.Password = sPwd;
                mXMPPCon.Status = "Online";
                mXMPPCon.Port = System.Convert.ToInt16("5222"); ;
                // mXMPPCon.AutoResolveConnectServer = true;
                mXMPPCon.AutoResolveConnectServer = false;
                mXMPPCon.ClientSocket.ConnectTimeout = 20000;

                mXMPPCon.Open();
                
            }
        }
        protected void OnXmppOnLogin(object o)
        {
            Presence p = new Presence(ShowType.chat, "Online");
            p.Type = PresenceType.available;

            mXMPPCon.Send(p);
            if (OnLogInSuccess != null)
            {
                OnLogInSuccess(this);
            }
        }
        protected void OnXmppAuthError(object sender, Element e)
        {
            if (OnLogInFailure != null)
            {
                OnLogInFailure(this);
            }
        }
        protected void OnXmppRegisterError(object sender, Element e)
        {
            Console.WriteLine("what");
        }

        protected void OnXmppError(object sender, Exception e)
        {
            Console.WriteLine("what");
        }

         protected void OnXmppSocketError(object sender, Exception e)
         {
              // when server doesn't answer, this event is called.
              Console.WriteLine("what {0}", e.Message);
         }

         protected void OnXmppClose(object o)
         {
              Console.WriteLine("what");
         }

         protected void OnConStateChanged(object sender, XmppConnectionState mXmppConState)
         {
              Console.WriteLine("XmppConnectionStateChanged: {0}", mXmppConState.ToString());
         }


        // 19-Mar-2008
        // Author: Warren Lee
        // Automatically accept subscription request
        //
        protected void OnXmppOnPresence(object sender, Presence pres)
        {
         }
        protected void OnPnmpMsgHandler(object sender, agsXMPP.protocol.client.Message msg)
        {

            string sCommand;
            if (OnReceiveMsg != null)
            {
                OnReceiveMsg(this, msg);

                if (msg.Type == MessageType.error)
                {
                    return;
                }
            }

            /***********************************************************
             * Processing received XMPP Message
             * 1. Get "Command" Tag Value
             * 2. Process Tag Message
             * 3. Send PNMP Message Class to DBProcessing Class
             * *********************************************************
             */

            try
            {
                sCommand = msg.SelectSingleElement("command", true).Value.ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return;
            }

            switch (sCommand)
            {
                default:
                    // handling invalid command
                    break;
            }
        }
    }
}
WonHyoung Lee                     Tel: +1 408 452 9900
CDI Technology, Inc.              email: peste@chol.com
Avatar
Jabberer #2
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
hm, you try to connect to a internal IP address with the emulator. We have never tried this, I don't know how networking in the emulators works exactly.

  • did you plain socket code connect to the same IP (192.168.0.12)?
  • Can you try to connect to the jabber.org or gtalk server with the emulator?
  • can you try to debug the connect with the agsXMPP source in ClientSocket.cs?
Software Developer
AG-Software
Avatar
peste89 #3
Member since May 2008 · 2 posts · Location: San Jose
Group memberships: Members
Show profile · Link to this post
Dear,

Yes, I tried to connect with a internal IP address with emulator.
I set Windows Mobile 6 Professional Emulator to use "Enable NE2000 PCMCIA network adaptor."
Then I can browse Internet with Internet Explorer in WM6 Emulator.

As your recommends, I tried to connect Gtalk Server. Yeah It worked.
So I thought that I had to run Server Program on other PC. Finally It worked when Server was running on other PC.
Thank you.

I retried to run Server and Client (WM6 emulator) on same PC.
But it didn't work.

But when I'm using a plain socket program and trying to connect even though server and client were running on same PC.
It worked.

====== plain socket program =======
          Socket m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

          // Set the remote IP address
          IPAddress ip = IPAddress.Parse("192.168.0.12");
          int iPortNo = System.Convert.ToInt16("5222");

          IPEndPoint ipEnd = new IPEndPoint(ip, iPortNo);

          m_clientSocket.Connect(ipEnd);

When I used XMPP library, I always got socket error "attempt to connected time out."
WonHyoung Lee                     Tel: +1 408 452 9900
CDI Technology, Inc.              email: peste@chol.com
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Did you try to debug agsXMPP?
I see no reason why it work with servers on the internet, but not with local server, or a server in your LAN.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS