Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
hooflak #1
Member since Aug 2013 · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: how to get message displayed on web page from xmppClient_OnMessage event
Hi All,
I must be missing something so hoping you can help.

I can successfully send and receive messages but when the xmppClient_OnMessage event is raised with my incoming message how can I display this message on my web page?  I see there is another way to do it with SignalR but is this the only way?  I am working with a database and lots of server side code so doing all the connections etc on the client side will be tough.   A basic example of what i am trying to achieve is.

  1. //login
  2. protected void Button1_Click(object sender, EventArgs e)
  3. {
  4.     xmppClientObj = new XmppClient { XmppDomain = "mydomain.com.au", Username = "user@mydomain.com.au", Password = "mypassword" };
  5.     SetLicense();
  6.     xmppClientObj.OnMessage += new EventHandler<MessageEventArgs>(xmppClient_OnMessage);
  7.     xmppClientObj.OnBeforeSasl += new EventHandler<Matrix.Xmpp.Sasl.SaslEventArgs>(xmppClient_OnBeforeSasl);
  8.     xmppClientObj.Open();
  9.     xmppClientObj.SendPresence(Show.chat, "Online");
  10. }
  11.  
  12.  
  13. //receive message and assign body to div so we can see it
  14. private void xmppClient_OnMessage(object sender, MessageEventArgs e)
  15. {
  16.     message.InnerText = e.Message.Body.ToString();
  17. }

and on the ASPX

  1.     <form id="form1" runat="server">
  2.     <div id="message" runat="server">
  3.     </div>
  4.         <div>     
  5.     <asp:Button ID="Button1" runat="server" Text="btnLogin" OnClick="Button1_Click" />
  6.     </div>
  7.     </form>
  8. </body>
  9. </html>

But the div "message" never gets updated with the incoming message even though it looks like it is being assigned.  Same if I try any other type of control.

Any help appreciated.
Thanks
This post was edited 4 times, last on 2013-08-28, 17:40 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
MatriX is running on the Webserver (IIS). MatriX has a realtiem connection to your XMPP server on IIS. This means it can send and receive messages at any time fully asynchronous in realtime

The problem you are facing is that HTTP by default is not real time. There is AJAX which can execute calls from the client to the server on command (user input) at any time. But this solves the problem only in one direction. You can send a message at any time in realtime over Ajax or runatserver command buttons.

Now you also need the opposite. You must notify the browser in realtime whenever a messages or any other XMPP event comes in. This technology is also called Reverse Ajax. And there is nothing in ASP.NET and most other web frameworks to solve this out of the box. Here SignalR comes in place which is a framework which can also call the Browser from the server side in realtime. It also does a great job when passing .NET object to Javascript.

There are other framworks which solve this Problem as well. Or you can also write your own layer for this. But I think SignalR does an awesome job and has a great community. But without a reverse Ajax (comet) layer there is no way to post the message from the server to the client in realtime.

Alex
Avatar
hooflak #3
Member since Aug 2013 · 2 posts
Group memberships: Members
Show profile · Link to this post
Edited.  Thanks
This post was edited on 2013-08-28, 23:38 by hooflak.
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
We can, but not in this short time frame.
When you are in hurry you should look for existing software which can be integrated and fits your requirements.

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: MatriX RSS