Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Michael_Heribert #1
Member since Dec 2015 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Problem connecting to server locally
Good evening,

I have just started working with agsXMPP recently and started learning with this tutorial:
http://www.codeproject.com/Articles/21267/Creating-a-Jabbe…

Having downloaded the sample file, it works perfectly fine with these parameters when connecting to an online jabber server, fex. jabber.de

  1. Jid jidSender = new Jid("username@jabber.de");
  2. XmppClientConnection xmpp = new XmppClientConnection();
  3. xmpp.Server = "jabber.de";
  4. xmpp.Username = "username";
  5. xmpp.Password = "Passwort";
  6. string Password = "Passwort"; // is to be used later in the listing
  7. xmpp.AutoResolveConnectServer = false;
  8. xmpp.ConnectServer = "85.214.196.40";

However, when I try to use my local ejabberd server, it does not connect properly:

  1. Jid jidSender = new Jid("123@hapi");
  2. XmppClientConnection xmpp = new XmppClientConnection();
  3. xmpp.Server = "hapi";
  4. xmpp.Username = "123";
  5. xmpp.Password = "Passwort";
  6. string Password = "Passwort";
  7. xmpp.AutoResolveConnectServer = false;
  8. xmpp.ConnectServer = "127.0.0.1";

Apart from the code you see above I have not changed anything in the listing from TheCodeProject.

When executing the code, XmppClientConnection xmpp.ConnectionState is set to "Connecting" and xmpp.Authenticated is "false".

Using Psi to connect to my local server, I had to modify the hosts file to enable the programme to resolve the pc name "hapi" or "localhost" to the right ip address... But for Psi, connecting with the credentials works now. Still I got these issues with the code above.
Is there anything I am missing out on??

Thanks in advance,
Michael_Heribert
This post was edited 3 times, last on 2015-12-31, 17:00 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
are you sure that your ejabberd listens on 127.0.0.1? And not on another network interface? Maybe your local v6 address?
Your code looks fine.

Alex
Avatar
Michael_Heribert #3
Member since Dec 2015 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thank you for your quick reply!

I think it should listen on 127.0.0.1:5222, at least testing with telnet worked. And Psi could connect with these parameters. Maybe there is something else blocking the connection? I tried turning off the windows firewall, but it didn't work either.

This is the complete programme:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using agsXMPP;
  5. using agsXMPP.protocol.client;
  6. using agsXMPP.Collections;
  7. using agsXMPP.protocol.iq.roster;
  8. using System.Threading;
  9.  
  10. namespace JabberClient
  11. {
  12.     class Program
  13.     {
  14.         static bool _wait;
  15.         static void Main(string[] args)
  16.         {
  17.             Console.Title = "Jabber Client";
  18.             Jid jidSender = new Jid("admin@hapi");
  19.             XmppClientConnection xmpp = new XmppClientConnection();
  20.             xmpp.Server = "hapi";
  21.             xmpp.Port = 5222;
  22.             xmpp.Username = "admin";
  23.             xmpp.Password = "pw";
  24.             xmpp.AutoResolveConnectServer = false;
  25.             xmpp.ConnectServer = "127.0.0.1";
  26.  
  27.             try
  28.             {
  29.                 xmpp.Open(jidSender.User, xmpp.Password);
  30.                 xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
  31.             }
  32.             catch (Exception e)
  33.             {
  34.                 Console.WriteLine(e.Message);
  35.             }
  36.  
  37.             // workaround, just waiting till the login and authentication is finished
  38.        
  39.             Console.Write("Wait for Login ");
  40.             int i = 0;
  41.             _wait = true;
  42.             do
  43.             {
  44.                 Console.Write(".");
  45.                 i++;
  46.                 if (i == 10)
  47.                     _wait = false;
  48.                 Thread.Sleep(500);
  49.             } while (_wait);
  50.             Console.WriteLine();
  51.  
  52.             Console.WriteLine("Login Status:");
  53.             Console.WriteLine("xmpp Connection State {0}", xmpp.XmppConnectionState);
  54.             Console.WriteLine("xmpp Authenticated? {0}", xmpp.Authenticated);
  55.             Console.WriteLine();
  56.  
  57.             Console.WriteLine("Sending Precence");
  58.             Presence p = new Presence(ShowType.chat, "Online");
  59.             p.Type = PresenceType.available;
  60.             xmpp.Send(p);
  61.             Console.WriteLine();
  62.  
  63.             xmpp.OnPresence += new PresenceHandler(xmpp_OnPresence);
  64.  
  65.             //wait until we received the list of available contacts
  66.        
  67.             Console.WriteLine();
  68.             Thread.Sleep(500);
  69.  
  70.             Console.WriteLine("Enter Chat Partner JID:");
  71.             string JID_Receiver = Console.ReadLine();
  72.             Console.WriteLine();
  73.  
  74.             Console.WriteLine("Start Chat");
  75.  
  76.             xmpp.MesagageGrabber.Add(new Jid(JID_Receiver), new BareJidComparer(), new MessageCB(MessageCallBack), null);
  77.  
  78.             string outMessage;
  79.             bool halt = false;
  80.             do
  81.             {
  82.                 Console.ForegroundColor = ConsoleColor.Green;
  83.                 outMessage = Console.ReadLine();
  84.                 if (outMessage == "q!")
  85.                 {
  86.                     halt = true;
  87.                 }
  88.                 else
  89.                 {
  90.                     xmpp.Send(new Message(new Jid(JID_Receiver),
  91.                                   MessageType.chat,
  92.                                   outMessage));
  93.                 }
  94.  
  95.             } while (!halt);
  96.             Console.ForegroundColor = ConsoleColor.White;
  97.  
  98.             xmpp.Close();
  99.         }
  100.      
  101.         static void xmpp_OnPresence(object sender, Presence pres)
  102.         {
  103.             Console.WriteLine("Available Contacts: ");
  104.             Console.WriteLine("{0}@{1}  {2}", pres.From.User, pres.From.Server, pres.Type);
  105.             //Console.WriteLine(pres.From.User + "@" + pres.From.Server + "  " + pres.Type);
  106.             Console.WriteLine();
  107.         }
  108.  
  109.         static void xmpp_OnLogin(object sender)
  110.         {
  111.             _wait = false;
  112.             Console.WriteLine("Logged In");
  113.         }
  114.  
  115.         static void MessageCallBack(object sender, agsXMPP.protocol.client.Message msg, object data)
  116.         {
  117.             if (msg.Body != null)
  118.             {
  119.                 Console.ForegroundColor = ConsoleColor.Red;
  120.                 Console.WriteLine("{0}>> {1}", msg.From.User, msg.Body);
  121.                 Console.ForegroundColor = ConsoleColor.Green;
  122.             }
  123.         }
  124.     }
  125. }

Michael
This post was edited 2 times, last on 2016-01-01, 19:31 by Michael_Heribert.
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Did you check if there is any XML flow between the client and the server? Look at the send and receive XML events.

Alex
Avatar
Michael_Heribert #5
Member since Dec 2015 · 3 posts
Group memberships: Members
Show profile · Link to this post
I finally found the reason for this issue:

I was developing on my laptop which is using Windows 10. Now that I could try it on my main pc, running Windows 7, it worked...

Thanks for your help though,
Michael_Heribert
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
there still must be a reason why it did not work on W10. It should work fine there as well.

Alex
Avatar
bk______ #7
Member since Feb 2016 · 3 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #1
Sorry for hijacking your question. Could I ask you which file you got that code from? I've been trying to start up my own client but am getting nowhere. Thanks
Avatar
Alex #8
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
browse our websites for MatriX and agsXMPP and you will find this code.
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