jabber.net不适用于vb.net

时间:2012-05-07 14:12:22

标签: asp.net

我正在尝试将jabber.net用于Web应用程序 我知道这是用于桌面应用程序,如下面给出的链接

http://www.codeproject.com/Articles/34300/Google-Chat-Desktop-Application-using-Jabber-Net

但是我发现了一篇与此相关的堆栈溢出帖子,它说有一个家伙用web应用程序实现了它

Web Chat Application - ASP.NET/Jabber/Ajax/WCF/Comet/ReverseAjax - Issues Faced - Seeking Insights

实际上代码项目代码是用c#

编写的
using System;    
using System.Collections;    
using System.Collections.Generic;    
using System.ComponentModel;    
using System.Data;    
using System.Drawing;    
using System.Text;    
using jabber.client;    
using System.Threading;    
using jabber.protocol.iq;    
using jabber;    
using Google.GData.Contacts;    
using Google.GData.Extensions;    
using jabber.protocol;

namespace WebApplication1    
{    
    public partial class _Default : System.Web.UI.Page    
    {    
        static ManualResetEvent done = new ManualResetEvent(false);    
        private jabber.client.JabberClient jabberClient1=new jabber.client.JabberClient();    

        protected void Page_Load(object sender, EventArgs e)
        {
            jabberClient1.OnMessage += new MessageHandler(jabberClient1_OnMessage);
            jabberClient1.OnDisconnect += new bedrock.ObjectHandler(jabberClient1_OnDisconnect);
            jabberClient1.OnError += new bedrock.ExceptionHandler(jabberClient1_OnError);
            jabberClient1.OnAuthError += new jabber.protocol.ProtocolHandler(jabberClient1_OnAuthError);
            jabberClient1.User = "sa";
            jabberClient1.Server = "gmail.com";
            jabberClient1.Password = "download";
            jabberClient1.Connect();
            jabberClient1.OnAuthenticate += new bedrock.ObjectHandler(jabberClient1_OnAuthenticate);
        }

        void jabberClient1_OnAuthenticate(object sender)
        {
            done.Set();
        }

        void jabberClient1_OnAuthError(object sender, System.Xml.XmlElement rp)
        {
            if (rp.Name == "failure")
            {
                Response.Write("Invalid User Name or Password");
            }
        }

        void jabberClient1_OnError(object sender, Exception ex)
        {
            Response.Write(ex.Message);
        }

        void jabberClient1_OnDisconnect(object sender)
        {
            Response.Write("Disconnected");
        }

        private void jabberClient1_OnMessage(object sender, jabber.protocol.client.Message msg)
        {
            Response.Write("Message Posted");
            //frmChat[(int)chatIndex[msg.From.Bare]].ReceiveFlag = true;
            //string receivedMsg = msg.From.User + " Says : " + msg.Body + "\n";
            //frmChat[(int)chatIndex[msg.From.Bare]].AppendConversation(receivedMsg);
            //frmChat[(int)chatIndex[msg.From.Bare]].Show();
        }
    }


}

所以我把它转换成vb.net就像这样

Imports System    
Imports System.Collections    
Imports System.Collections.Generic    
Imports System.ComponentModel    
Imports System.Data    
Imports System.Drawing    
Imports System.Text    
Imports jabber.client    
Imports System.Threading    
Imports jabber.protocol.iq    
Imports jabber    
Imports Google.GData.Contacts    
Imports Google.GData.Extensions    
Imports jabber.protocol    

Public Class GtalkIntegration    
    Inherits System.Web.UI.Page    
    Shared done As New ManualResetEvent(False)    
    Private WithEvents jabberClient1 As New jabber.client.JabberClient()    

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AddHandler jabberClient1.OnMessage, AddressOf jabberClient1_OnMessage
        AddHandler jabberClient1.OnDisconnect, AddressOf jabberClient1_OnDisconnect
        AddHandler jabberClient1.OnError, AddressOf jabberClient1_OnError
        AddHandler jabberClient1.OnAuthError, AddressOf jabberClient1_OnAuthError
        jabberClient1.User = "sa"
        jabberClient1.Server = "gmail.com"
        jabberClient1.Password = "download"
        jabberClient1.Connect()
        AddHandler jabberClient1.OnAuthenticate, AddressOf jabberClient1_OnAuthenticate
    End Sub

    Private Sub jabberClient1_OnAuthenticate(ByVal sender As Object)
        done.[Set]()
    End Sub

    Private Sub jabberClient1_OnAuthError(ByVal sender As Object, ByVal rp As System.Xml.XmlElement)
        If rp.Name = "failure" Then
            Response.Write("Invalid User Name or Password")
        End If
    End Sub

    Private Sub jabberClient1_OnError(ByVal sender As Object, ByVal ex As Exception)
        Response.Write(ex.Message)
    End Sub

    Private Sub jabberClient1_OnDisconnect(ByVal sender As Object)
        Response.Write("Disconnected")
    End Sub

    Private Sub jabberClient1_OnMessage(ByVal sender As Object, ByVal msg As jabber.protocol.client.Message)
        Response.Write("Message Posted")
        'frmChat[(int)chatIndex[msg.From.Bare]].ReceiveFlag = true;
        'string receivedMsg = msg.From.User + " Says : " + msg.Body + "\n";
        'frmChat[(int)chatIndex[msg.From.Bare]].AppendConversation(receivedMsg);
        'frmChat[(int)chatIndex[msg.From.Bare]].Show();
    End Sub
End Class

但它给我的错误就像

连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机无法响应而建立连接失败

请提前帮助我们帮助

1 个答案:

答案 0 :(得分:2)

请务必参考jabber-net.dll,zlib.net.dll和netlib.Dns.dll。