Not logged in. · Lost password · Register
Forum: agsXMPP RSS
thread completes, can only send and receive message once
Avatar
Vontux #1
Member since Jul 2013 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: agsxmpp trouble Sending and receiving messages more than once
Hello, I'm working on a simple test application to help me get the basics of agsxmpp. I'm having difficulty keeping the thread open to send or receive messages more than once. Below is my code, I've done everything I can think of to make this work, so any help would be greatly appreciated. This is a simple gtk# application running on mono 4.0.

  1. using System;
  2. using System.ComponentModel;
  3. using System.Threading;
  4. using Gtk;
  5. using agsXMPP;
  6. using agsXMPP.protocol.client;
  7. using agsXMPP.protocol.iq.roster;
  8. using agsXMPP.protocol.iq.vcard;
  9.  
  10. public partial class MainWindow: Gtk.Window
  11. {   
  12.     Gtk.TextBuffer buffer;
  13.     XmppClientConnection xmpp;
  14.     Thread worker;
  15.     ManualResetEvent mre;
  16.  
  17.     public MainWindow (): base (Gtk.WindowType.Toplevel)
  18.     {
  19.         Build ();
  20.         xmpp = new XmppClientConnection();
  21.         worker = new Thread(Login);
  22.         worker.Start();
  23.     }
  24.    
  25.     protected void OnDeleteEvent (object sender, DeleteEventArgs a)
  26.     {
  27.         Application.Quit ();
  28.         a.RetVal = true;
  29.     }
  30.  
  31.  
  32.     void Login() {
  33.  
  34.         xmpp.Server = "gmail.com";
  35.         xmpp.ConnectServer = "talk.google.com";
  36.         xmpp.Username = "myUsername";
  37.         xmpp.Password = "mypwd";
  38.         xmpp.Open();
  39.         xmpp.KeepAlive = true;
  40.         agsXMPP.Jid JID = new Jid("myUsername@gmail.com");
  41.         
  42.  
  43.         agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
  44.         msg.Type = agsXMPP.protocol.client.MessageType.chat;
  45.         msg.To = JID;
  46.         msg.Body = "Test software test...English you fail me again! " + DateTime.Now.ToString();
  47.  
  48.         buffer = textview4.Buffer;
  49.  
  50.  
  51.         xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); buffer.Text += "kinda round about damn"; };
  52.         xmpp.OnMessage += new agsXMPP.protocol.client.MessageHandler(GrabMessage);
  53.         mre = new ManualResetEvent (false);
  54.         mre.WaitOne ();
  55.  
  56.     }
  57.  
  58.     void GrabMessage (object sender, agsXMPP.protocol.client.Message msg)
  59.     {
  60.         buffer.Text += " From: " + msg.From + " " + msg.Body;
  61.     }
  62.     protected void OnTogglebutton1Clicked (object sender, EventArgs e)
  63.     {
  64.         mre.Close();
  65.         worker.Abort();
  66.     }
  67.  
  68. }
This post was edited 2 times, last on 2013-07-17, 00:18 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I see nothing wrong here, but I am not an GTK expert.
What is the output from the Send and Receive Xml handlers?

Alex
Avatar
Vontux #3
Member since Jul 2013 · 3 posts
Group memberships: Members
Show profile · Link to this post
Quote by Alex on 2013-07-17, 00:18:
I see nothing wrong here, but I am not an GTK expert.
What is the output from the Send and Receive Xml handlers?

Alex

I'm afraid I don't know how to access the Send and Receive Xml handlers. Could you please describe how to do so, I will then put up the output, thanks for your quick reply.
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
see: http://forum.ag-software.net/post/3796;nocount
Avatar
Vontux #5
Member since Jul 2013 · 3 posts
Group memberships: Members
Show profile · Link to this post
Quote by Alex:
see: http://forum.ag-software.net/post/3796;nocount

Thanks, here is the output:

The "OnWrite" event appears to fire two times
First Fire:
<stream:stream to='gmail.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

Second Fire:
<stream:stream to='gmail.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

The "OnReadXml" Event appears to fire once:

OnReadXml Output Begin
<stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="gmail.com" id="E1A9C68454467B8B" version="1.0" >
After that, the application crashes, from an exception that I can only assume was caused by the addition of the "OnReadXml" and "OnWriteXml" events. Below is the exception thrown:
Stacktrace:

  at (wrapper managed-to-native) Gtk.Application.gtk_main () <IL 0x00022, 0xffffffff>
  at Gtk.Application.Run () <IL 0x00000, 0x0001f>
  at TestAgsGTK.MainClass.Main (string[]) [0x00011] in /home/vontux/Development/Projects/DOTNET/TestAgsGTK/TestAgsGTK/Main.cs:13
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

    /usr/bin/mono() [0x80e6431]
    /usr/bin/mono() [0x812697c]
    /usr/bin/mono() [0x8062aff]
    [0xb774340c]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(+0x1d8baf) [0xb5bf3baf]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(+0x1d8c68) [0xb5bf3c68]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(+0x1d93f3) [0xb5bf43f3]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(+0x1db1f1) [0xb5bf61f1]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(gtk_text_layout_validate_yrange+0x1f8) [0xb5c12638]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(+0x207afa) [0xb5c22afa]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(+0x20a1bb) [0xb5c251bb]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(+0x20a20c) [0xb5c2520c]
    /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0(+0x15094) [0xb6367094]
    /lib/i386-linux-gnu/libglib-2.0.so.0(+0x43c30) [0xb54c2c30]
    /lib/i386-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x143) [0xb54c59e3]
    /lib/i386-linux-gnu/libglib-2.0.so.0(+0x46d80) [0xb54c5d80]
    /lib/i386-linux-gnu/libglib-2.0.so.0(g_main_loop_run+0x7b) [0xb54c61db]
    /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0(gtk_main+0xb0) [0xb5b503a0]
    [0xb514655c]
    [0xb51464e0]
    [0xb684e058]
    [0xb684e1ce]
    /usr/bin/mono() [0x8066dcc]

Debug info from gdb:

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
No threads.

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

I did go ahead and write a Winforms version of this test app which also crashes with the addition of the "OnReadXml" and "OnWriteXml" events. I can post it's code, its output and its exception if you think that debugging a winforms based app would be less problematic than the gtk# one. I'm assuming the same problem is affecting both.
Avatar
Alex #6
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The stream header should be sent only once. Its strange that you get the first OnWrite twice.
Can you try to run the MiniClient Winforms example which is included with the download?

This can also be a threading issue. Can you try to execute your login function from a command button instead of a Thread?
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