📄 jabberstream.cs
字号:
using System;
using System.Xml;
using System.Threading;
using System.Xml.Serialization;
using ENC=System.Text.Encoding;
using gowk.core.packets;
using gowk.net.Sockets;
using gowk.net;
namespace gowk.core
{
public class JabberStream
{
private ISocket isock;
private string _from,_to,_id,_lang,_version;
public event System.EventHandler JabberStreamEnd;
public JabberStream()
{
}
public ISocket Socket
{
get{return this.isock;}
set{this.isock=value;}
}
public byte[] Read()
{
/* if(this.isock==null)
{
throw new System.NullReferenceException();
}*/
byte[] bf=new byte[1024];
int cnt=0;
try
{
cnt=this.isock.Receive(bf);
}
catch(System.Net.Sockets.SocketException se)
{
System.Diagnostics.Trace.WriteLine(se.Message);
this.InvokeEndOfStream();
return null;
}
catch(System.Exception ex)
{
gowk.utility.Diagnostics.Debug.Write(ex);
this.InvokeEndOfStream();
return null;
}
if(cnt==0)
{
this.InvokeEndOfStream();
return null;
}
byte[] ret=new byte[cnt];
Buffer.BlockCopy(bf,0,ret,0,cnt);
return ret;
}
private void InvokeEndOfStream()
{
System.Diagnostics.Trace.WriteLine("end of stream");
if(this.JabberStreamEnd!=null)
this.JabberStreamEnd(this,System.EventArgs.Empty);
}
public int Write(byte[] bytes)
{
if(this.Socket==null)return -1;
if(!this.Socket.Connected)return -1;
try
{
return isock.Send(bytes);
}
catch(System.Net.Sockets.SocketException se)
{
if(se.ErrorCode==10054)
{
}
else if(se.ErrorCode==10053)
{
}
System.Diagnostics.Trace.WriteLine(se.Message);
System.Diagnostics.Trace.WriteLine(se.ErrorCode.ToString());
this.InvokeEndOfStream();
// throw;
}
catch(System.Exception ex)
{
gowk.utility.Diagnostics.Debug.Write(ex);
this.InvokeEndOfStream();
}
return -1;
}
public int Write(string str)
{
return this.Write(ENC.UTF8.GetBytes(str));
}
#region
public string Form
{
get{return this._from;}
set{this._from=value;}
}
public string To
{
get{return this._to;}
set{this._to=value;}
}
public string ID
{
get{return this._id;}
set{this._id=value;}
}
public string Lang
{
get{return this._lang;}
set{this._lang=value;}
}
public string Version
{
get{return this._version;}
set{this._version=value;}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -