Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
owen #1
Member since Nov 2006 · 21 posts · Location: UK
Group memberships: Members
Show profile · Link to this post
Subject: Receiving messages - easy again?
OK, so I'm doing a simple VB.NET desktop app to send & receive between two GTalk users. So far, I can Login, Authenticate, Connect, send my presence, and send a message successfully to a GTalk client on another computer.

But when that GTalk client replies to my message, I don't receive it.  In fact, I dont seem able to detect ANY incoming messages.

From what I've seen, this is meant to be done using callback events to react to incoming messages. The problem is, it just doesn't hit my MessageCallback procedure...  and I've no idea why.  (Again, I'm sure it's something really simple, so I apologise in advance...)

________

  Private Sub MessageCallback(ByVal sender As Object, ByVal msg As agsXMPP.protocol.client.Message, ByVal data As Object)       
      ' Should pop up a message box when message received ... but doesn't!
        Dim info As String = msg.From.User & " said: " & msg.Body
        MsgBox(info)
    End Sub

    Private Sub PresenceCallback(ByVal sender As Object, ByVal pres As agsXMPP.protocol.client.Presence, ByVal data As Object)      
     ' pops up a message box when status changes - seems to work ok
        Dim info As String = pres.From.Bare & " is " & pres.Status
        MsgBox(info)
    End Sub

    Private Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoginButton.Click
        With XMPP
            Dim MyJid As New Jid("supergeese@gmail.com")

            ' --- callback for messages received (DOES NOT WORK!) ---
            Dim cb As New agsXMPP.MessageCB(AddressOf MessageCallback)
            .MesagageGrabber.Add(MyJid, cb, Nothing)

            ' --- callback for presence changes (WORKS FINE) ---
            Dim pcb As New agsXMPP.PresenceCB(AddressOf PresenceCallback)
            .PresenceGrabber.Add(MyJid, pcb, Nothing)

            .Server = "gmail.com"
            .ConnectServer = "talk.google.com"
            .Username = "myself"
            .Password = "mypassword"
            .Port = "5222"
            .UseSSL = False
            .Status = "Online"
            .Priority = 5
            .AutoResolveConnectServer = True

            .AutoRoster = True

            .RegisterAccount = False
            .Show = agsXMPP.protocol.client.ShowType.chat

            .Open()
        End With
    End Sub
Avatar
owen #2
Member since Nov 2006 · 21 posts · Location: UK
Group memberships: Members
Show profile · Link to this post
I solved my own problem.  I was putting my own JID here:

.MesagageGrabber.Add(MyJid, cb, Nothing)


...but I should have been using the sender's JID instead.

Sorry about that.



Owen
Avatar
Alex #3
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hi Owen,

You receive all Messages in the OnMessage event of XmppClientConnection.

The MessageGrabber is a small utility class to grab messages from only a special bare or full Jid.
Most developers use this directly in their chat/message windows. Its much easier than passing thru the events from the main application from.

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