📄 jabberclient.cs
字号:
using System;
using System.IO;
using System.Xml;
using System.Threading;
using System.Windows.Forms;
using gowk.core.managers;
using gowk.core.packets;
using gowk.net.Sockets;
using gowk.net;
namespace gowk.core
{
/// <summary>
/// JabberClient 的摘要说明。
/// </summary>
public class JabberClient:JabberEndPoint
{
private string password;
private int port=5222;
private Control control;
private Proxy proxy;
public JabberClient()
{
}
/// <summary>
/// connect to the server
/// set the Proxy property to null if there is not proxy used
/// </summary>
public void Connect()
{
/* if(this.Socket!=null)
{
try
{
this.Socket.Close();
}
catch(System.Exception ex)
{
System.Diagnostics.Debug.Assert(false);
}
}*/
this.Socket=new GSecureSocket(null);
this.Socket.Proxy=this.Proxy;
this.Socket.Connect(this.Jid.Server,this.Port);
this.State=State.StartStream;
this.JabberStream.Socket=this.Socket;
this.JabberStreamWriter.StartStream(this.Jid.Server);
this.JabberMessageWatcher.Start();
}
public void Disconnect()
{
//send close stream
if(this.Socket!=null)
{
this.Socket.Close();
}
this.State=State.Disconnected;
this.JabberMessageWatcher.Stop();
}
#region properties
/// <summary>
/// the server port,
/// set it to 5223 while use ssl,else 5222
/// </summary>
public int Port
{
get{return this.port;}
set{this.port=value;}
}
/// <summary>
/// if there is not proxy used,set this property to null,Nothing in vb.net
/// </summary>
public Proxy Proxy
{
get{return this.proxy;}
set{this.proxy=value;}
}
/// <summary>
/// the user password
/// </summary>
public string Password
{
get{return this.password;}
set{this.password=value;}
}
/// <summary>
/// the control to invoke events,it usefull for ui updating
/// </summary>
public Control Control
{
get{return this.control;}
set{this.control=value;}
}
#endregion
}
/// <summary>
/// the eventhandler for fire exception while receive invalidate xml stanza
/// </summary>
public delegate void JabberStreamExceptionEventHander(JabberEndPoint jep,StreamException e);
public delegate void JabberEventHandler(JabberEventArgs e);
public delegate void JabberCallBack(JabberEventArgs e);
/// <summary>
///
/// </summary>
public class JabberEventArgs:System.EventArgs
{
private Packet pack,rp;
/// <summary>
///
/// </summary>
/// <param name="p">the packet you sended or you would like to send/param>
public JabberEventArgs(Packet p)
{
this.pack=p;
}
/// <summary>
/// to construct a eventargs for timed event
/// </summary>
/// <param name="p"></param>
/// <param name="rp"></param>
public JabberEventArgs(Packet p,Packet rp):this(p)
{
this.rp=rp;
}
/// <summary>
/// the packet you sended or you would like to send
/// </summary>
public Packet Packet
{
get{return this.pack;}
}
/// <summary>
/// returns the reply packet if succed else null if timeout,while you send a packet with a call back.
/// you must not evaluate it while you send a packet
/// </summary>
public Packet ReplyPacket
{
get{return this.rp;}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -