Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Page:  1  2  next
Avatar
acmixer #1
Member since Aug 2006 · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: (ASPX) IT DOES NOT CONNECT
Hello, this post I am translating it in google, because I do not speak English, my problem is that I use agsXMPP.dll in a page aspx written in Visual BASIC .net 2005, but 90% on the attempts are not connected….aid please….

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        With oConn_XMPP

            'Usuario con el que se conecta
            Jid = New agsXMPP.Jid(sUsuario_Conversa)
            cb = New agsXMPP.MessageCB(AddressOf MessageCallback)
            .MesagageGrabber.Add(Jid, cb, Nothing)

            .Server = "gmail.com"
            .ConnectServer = "talk.google.com"
            .Username = txt_Usuario.Text
            .Password = txt_Clave.Text
            .Port = "5222"
            .UseSSL = False
            .Status = "Online"
            .Priority = 5
            .AutoResolveConnectServer = True
            .RegisterAccount = True
            .Show = agsXMPP.protocol.client.ShowType.chat
            .Open()

            If .Authenticated Then
                Button1.Enabled = False
                Button3.Enabled = True
            End If

        End With

        Session("Conn") = oConn_XMPP

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        oConn_XMPP = Session("Conn")
        With oConn_XMPP
            If .XmppConnectionState.Connected = agsXMPP.XmppConnectionState.Connected Then
                oMsg_XMPP = New agsXMPP.protocol.client.Message(sUsuario_Conversa, txt_msg.Text)

                .Send(oMsg_XMPP.InnerXml)
                txt_Chat.Text += UCase(txt_Usuario.Text) & " : " & txt_msg.Text & Chr(13) & Chr(10)
            End If
        End With
        Session("Conn") = oConn_XMPP

    End Sub

    Private Sub MessageCallback(ByVal sender As Object, ByVal msg As agsXMPP.protocol.client.Message, ByVal data As Object)
        txt_Chat.Text += msg.From.User & " said: " & msg.Body & Chr(13) & Chr(10)
    End Sub


This post was edited on 2006-08-09, 08:52 by acmixer.
Avatar
Jabberer #2
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Hello,

the open methos is asynchronous. That means after the open method returns you are not connected.
And this is the reason why this code will fail:

  1. If .Authenticated Then
  2.    Button1.Enabled = False
  3.    Button3.Enabled = True
  4. End If

When you are connected you will get the OnLogin event of XmppClientConnection. So check the OnLogin event.
Software Developer
AG-Software
Avatar
acmixer #3
Member since Aug 2006 · 5 posts
Group memberships: Members
Show profile · Link to this post
ok. thank you very much
Avatar
Awan #4
Member since Sep 2006 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Can't Recieve Reply from google talk users
Hi
I have developed an aspx application which connects to the google talk server.
It logs in and sends presence succesfully. It also sends messages to google users which are delivered to them successfully.
But the reply from other google talk users doesn't reach back ie The "xmpp_OnMessage" event is never called.

   xmpp.OnMessage += new agsXMPP.XmppClientConnection.MessageHandler(xmpp_OnMessage);

The problem could be the way asp.net works as it forgets everything about a request after sending the response.
How can i maintain a live connection with google talk server from  my web application ?
Please help...
Thanks in advance.

-Awan
Avatar
Alex #5
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

Google Talk routes messages only between users which have mutual subscription. So make your that the subscription is OK.
If you can send messages in one direction then your code should be OK and your session is alive. So it could be the problem i described above.
In an ASPX application you have to store the XmppClientConnection object in your session. And of course you will not get any event until you reload the page. And reloading the page all the makes no sense to me. ASPX + AJAX is the best solution here.

Alex
Avatar
Awan #6
Member since Sep 2006 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex
Thanks for the reply.
The mutual subscription is ok as the same code works fine in a desktop application.

I have created XmppClientConnection as a static variable so that its a global object and retain its value between the subsequent round trips to the server.
Offcourse you are right reloading all the page makes no sense, thats why I am using ATLAS update panel in asp.net and using a timer control to update that panel.
But the problem is that "xmpp_OnMessage" event is never called.
Although i can trigger the timer event if the "xmpp_OnMessage" event is called but as this event is never raised and i cant know if any message has arrived or not?

Can i manually read the message from XmppClientConnection object? using some command like XmppClientConnection.Read() etc...

Waiting for tips from your side.

-Awan
Avatar
Alex #7
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello Awan,

no there is no way to get the message stanzas without the event.
It's hard to find the problem without the source code. If you have some working example code then we could probably take a look at it.

Alex
Avatar
Awan #8
Member since Sep 2006 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hello Alex!
Here I am posting the code.
I cant figure out how to capture the event when the page is posted back to client. (As asp.net works in disconnected way).
As if the message from other user comes when the page has been rendered to the client browser, how wil the event be raised and how that message will be displayed to the client browser.
Please check the code, and update it if possible to capture the "xmpp_OnMessage" event....



///////////////////////////////GoogleClient.aspx
<%@ Page Language="C#" validateRequest="false" AutoEventWireup="true" CodeFile="GoogleClient.aspx.cs" Inherits="GoogleClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server"> <atlas:ScriptManager ID="ScriptManager1" runat="server" />
   
    <atlas:UpdatePanel ID="pnl1" runat="server" Mode="conditional">   
    <ContentTemplate>   
    <div>
    <atlas:TimerControl ID="AtlasTimer1" runat="server" Enabled="False" Interval="5000" OnTick="UpdateTimestamp"></atlas:TimerControl>   
     <asp:Label ID="Timestamp" runat="server"></asp:Label>&nbsp;<br />
      <asp:Label ID="Label1" runat="server" Text="Login" Width="44px"></asp:Label>&nbsp;
                <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
                <br />
                <asp:Label
                    ID="Label2" runat="server" Text="Password" Width="44px"></asp:Label><asp:TextBox ID="txtPassword"   runat="server" TextMode="Password" Width="141px"></asp:TextBox>
                <asp:Button ID="btnLogin" runat="server" OnClick="btnLogin_Click" Text="Login" />
                <asp:Button ID="btnLogout" runat="server" OnClick="btnLogout_Click" Text="Logout" />
                <br />
                </div>
                <div>               
               
        <asp:Label ID="Label5" runat="server" Text="User To Send To"></asp:Label>
        <asp:TextBox ID="txtUserToSendTo" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtMessageToSend" runat="server"></asp:TextBox>
        <asp:Button ID="btnSendMessage" runat="server" Text="Send" OnClick="btnSendMessage_Click" /><br />
       
                <asp:Label id="Label3" runat="server" Text="Console" Width="44px"></asp:Label>
                <asp:TextBox ID="txtDebug" runat="server" TextMode="MultiLine" Height="67px" Width="259px" ></asp:TextBox>&nbsp;<br />                &nbsp;        
          
    </div>
    </ContentTemplate>
    </atlas:UpdatePanel>
    </form>
</body>
</html>

///////////////////////////////GoogleClient.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using agsXMPP;
using agsXMPP.protocol;
using agsXMPP.protocol.iq;
using agsXMPP.protocol.iq.roster;
using agsXMPP.protocol.iq.agent;
using agsXMPP.Xml.DomParser;

public partial class GoogleClient: System.Web.UI.Page
{
    private static XmppClientConnection xmpp;
    static string debugText = "aa";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void UpdateTimestamp(object sender, EventArgs args)
    {
         Timestamp.Text = DateTime.Now.ToLongTimeString();
         TextBox1.Text = debugText + DateTime.Now.ToString();
        
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        debugText = "";
        xmpp = new XmppClientConnection();

        xmpp.OnReadXml += new agsXMPP.XmlHandler(xmpp_OnReadXml);
        xmpp.OnWriteXml += new agsXMPP.XmlHandler(xmpp_OnWriteXml);
        xmpp.OnLogin += new agsXMPP.ObjectHandler(xmpp_OnLogin);
        xmpp.OnMessage += new agsXMPP.XmppClientConnection.MessageHandler(xmpp_OnMessage);
        xmpp.OnError += new agsXMPP.ErrorHandler(xmpp_OnError);

        xmpp.Port = 5222;
        xmpp.UseSSL = false;
        xmpp.ConnectServer = "talk.google.com";
        xmpp.Server = "gmail.com";
        xmpp.Username = txtUserName.Text;
        xmpp.Password = txtPassword.Text;
        xmpp.Resource = "JonJab";

        try
        {
            xmpp.Open();
        }
        catch (Exception ex)
        {
            // MessageBox.Show(ex.Message);
        }

    }
    protected void btnLogout_Click(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
    private void xmpp_OnError(object sender, Exception ex)
    {

    }

    private void xmpp_OnReadXml(object sender, string xml)
    {
        debugText += "RECV XML: " + xml;// + System.Environment.NewLine;
        txtDebug.Text = debugText;
    }

    private void xmpp_OnWriteXml(object sender, string xml)
    {
        debugText += "SEND XML: " + xml;// + System.Environment.NewLine;
        txtDebug.Text = debugText;

    }
    private void xmpp_OnLogin(object sender)
    {
        debugText += "we are logged in to TalkShak server now";//+ System.Environment.NewLine;
        debugText += "set presence";//+ System.Environment.NewLine;
        xmpp.SendMyPresence();
        txtDebug.Text = debugText;
    }
    private void xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
    {
         txtDebug.Text = "Got message : " + msg.Body;
    }

    protected void btnSendMessage_Click(object sender, EventArgs e)
    {
        xmpp.Send(new agsXMPP.protocol.client.Message(txtUserToSendTo.Text, agsXMPP.protocol.client.MessageType.chat, txtMessageToSend.Text));       
    }
}
//////////////////////////////////////

-Awan
Avatar
Alex #9
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

you have to cache the XmppClientConnection and retrieve it from the cache/session on every page load. Only if the object does not exist you have to create a new instance. SO use something like this:

  1. lock (Cache)
  2. {
  3.     if (Cache.Get("XmppCon") != null)
  4.     {
  5.         xmppCon = (XmppClientConnection)Cache.Get("XmppCon");
  6.     }
  7.     else
  8.     {
  9.         xmppCon = new XmppClientConnection();
  10.         Cache.Insert("XmppCon", xmppCon);
  11.     }
  12. }

Alex
Avatar
Stranger #10
Member since Aug 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Subject: Can't connect t0 GoogleTalk
Using the miniclient whenever I try to get connected I get the following Debug info
SEND: <stream:stream to='gmail.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
RECV: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="gmail.com" version="1.0" id="0C5C21114FB66D91" >
RECV: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required /></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-GOOGLE-TOKEN</mechanism></mechanisms></stream:features>
SEND: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />

I'm actually stuck developing a webclient for googletalk.When I try to connect using the code above I don get any onLogin event get fired.onWriteXml even What I get is :
<stream:stream to='gmail.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
Can anybody tell me what else I'm missing here.
Avatar
Alex #11
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
are you using .NET 1.1 or 2.0?
It looks like it hangs during the TLS negotiation.

Alex
Avatar
Stranger #12
Member since Aug 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex for so quick a reply.
I'm using .Net 2.0.
Can u tell me what cud be possible reason why I'm facing the issue you are talking about ? How can I solve it ?!
Avatar
Alex #13
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

i just connected to GTalk with the latest MiniClient without any problems.
Can you try to debug the MiniClient and the library?

Alex
Avatar
Stranger #14
Member since Aug 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Alex,
I tried it at home and I got connected from MiniClient.
But from office I'm still stuck at the same point.I closed all my firewalls and virus guard and still no luck.
after Receiving
RECV: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
I get disconnected and "OnClose" is fired.
Can U tell me what actually I'm missing here !!
Avatar
Alex #15
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

thee must be something wrong on your office machine.
Sorry but i can't help you much there. The only way to find the problem would be to debug the code step by step.

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:
Page:  1  2  next
Forum: agsXMPP RSS