Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Mats #1
Member since Nov 2013 · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: FireOnError: Matrix.XmppStreamException: Unable to send data. The XMPP Stream is inactive
Hi!

The following code succeeds to send a message when the _xmppClient.OnRosterEnd event occurs.
However, when the Button1_Click event occurs I get the following:
  1. FireOnError: Matrix.XmppStreamException: Unable to send data. The XMPP Stream is inactive

Here is the complete code. Any ideas of why this behaviour?

  1. public partial class Chat : System.Web.UI.Page
  2.     {
  3.         private string API_KEY = "mykey here..";
  4.         private string API_SECRET = "Secret here";
  5.         private string AUTH_TOKEN = "";
  6.  
  7.         // instantiate a new XmppClient first
  8.         XmppClient _xmppClient = new XmppClient();
  9.  
  10.         string lic = @"license..+E0A=";
  11.  
  12.  
  13.         protected void Page_Load(object sender, EventArgs e)
  14.         {
  15.             if (!IsPostBack)
  16.             {
  17.                 using (var userContext = new UsersContext())
  18.                 {
  19.                     var userProfile = userContext.UserProfiles.SingleOrDefault(u => u.UserName == User.Identity.Name);
  20.                     AUTH_TOKEN = userProfile.AuthToken;
  21.                 }
  22.                 Matrix.License.LicenseManager.SetLicense(lic);
  23.                
  24.  
  25.                 _xmppClient.OnReceiveXml += new EventHandler<TextEventArgs>(XmppClientOnReceiveXml);
  26.                 _xmppClient.OnSendXml += new EventHandler<TextEventArgs>(XmppClientOnSendXml);
  27.                
  28.                 _xmppClient.OnBeforeSasl += xmppClient_OnBeforeSasl;
  29.                
  30.                 _xmppClient.SetXmppDomain("chat.facebook.com");
  31.                 _xmppClient.Port = 5222;
  32.                 _xmppClient.OnError += xmppClient_OnError;
  33.                 _xmppClient.Status = "I'm chatty";
  34.                 _xmppClient.Show = Matrix.Xmpp.Show.chat;
  35.                 _xmppClient.OnRosterEnd += xmppClient_OnRosterEnd;
  36.                 _xmppClient.Open();
  37.                 Label1.Text = "Connected";
  38.             }
  39.         }
  40.  
  41.         private void xmppClient_OnRosterEnd(object sender, Matrix.EventArgs e)
  42.         {
  43.             var msg = new Matrix.Xmpp.Client.Message
  44.             {
  45.                 Type = MessageType.chat,
  46.                 To = "-100006687034052@chat.facebook.com",
  47.                 Body = "Chat message from app. Good stuff."
  48.             };
  49.             _xmppClient.Send(msg);
  50.             System.Diagnostics.Debug.WriteLine("Message sent?");
  51.         }
  52.  
  53.         private void xmppClient_OnBeforeSasl(object sender, Matrix.Xmpp.Sasl.SaslEventArgs e)
  54.         {
  55.             e.Auto = false;
  56.             e.SaslMechanism = Matrix.Xmpp.Sasl.SaslMechanism.X_FACEBOOK_PLATFORM;
  57.  
  58.             e.SaslProperties = new Matrix.Xmpp.Sasl.Processor.Facebook.FacebookProperties
  59.             {
  60.                 ApiKey = API_KEY,
  61.                 ApiSecret = API_SECRET,
  62.                 AccessToken = AUTH_TOKEN
  63.             };
  64.         }
  65.  
  66.         void XmppClientOnSendXml(object sender, TextEventArgs e)
  67.         {
  68.             AddDebug("SEND: " + e.Text);
  69.         }
  70.  
  71.         void XmppClientOnReceiveXml(object sender, TextEventArgs e)
  72.         {
  73.             AddDebug("RECV: " + e.Text);
  74.         }
  75.  
  76.         void AddDebug(string debug)
  77.         {
  78.             System.Diagnostics.Debug.WriteLine(debug);
  79.         }
  80.         private void xmppClient_OnError(object sender, ExceptionEventArgs e)
  81.         {
  82.             System.Diagnostics.Debug.WriteLine("OnError = " + e.Exception.Message);
  83.         }
  84.  
  85.         protected void Button1_Click(object sender, EventArgs e)
  86.         {
  87.             var msg = new Matrix.Xmpp.Client.Message
  88.             {
  89.                 Type = MessageType.chat,
  90.                 To = "-100006687034052@chat.facebook.com",
  91.                 Body = "Chat message from app"
  92.             };
  93.             _xmppClient.Send(msg);
  94.         }
  95.  
  96.     }
This post was edited on 2013-11-02, 20:19 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You should put your XmppClient object to a session and always receive it from there when you access it.
Have you looked at the WebClient example with SignalR?

Alex
Avatar
Mats #3
Member since Nov 2013 · 2 posts
Group memberships: Members
Show profile · Link to this post
Ah, I see. I (obviousely)thought it was able to keep the state in the page.
What WebClient example are you referring to?
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by Mats:
Ah, I see. I (obviousely)thought it was able to keep the state in the page.
websites are "stateless", this is why you have to use sessions. MatriX is running in codebehind on the web server.

Quote by Mats:
What WebClient example are you referring to?

when you download the complete SDK it comes with many examples. One is a WebClient.

See also:
http://www.ag-software.net/matrix-xmpp-sdk/download/
http://www.ag-software.net/2012/08/20/web-clients-with-mat…
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: MatriX RSS