SuperSocket笔记
Posted ljsoftware
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SuperSocket笔记相关的知识,希望对你有一定的参考价值。
一、起始结束符
public class MyRequestInfo : IRequestInfo
{
public string Key { get; set; }
public byte[] Body { get; set; }
public MyRequestInfo(byte[] readBuffer)
{
Body = readBuffer;
}
}
class MyReceiveFilter : BeginEndMarkReceiveFilter<MyRequestInfo>
{
//开始和结束标记也可以是两个或两个以上的字节
private readonly static byte[] BeginMark = new byte[] { (byte)‘<‘ };
private readonly static byte[] EndMark = new byte[] { (byte)‘>‘ };
public MyReceiveFilter()
: base(BeginMark, EndMark) //传入开始标记和结束标记
{
}
protected override MyRequestInfo ProcessMatchedRequest(byte[] readBuffer, int offset, int length)
{
//TODO: 通过解析到的数据来构造请求实例,并返回
return new MyRequestInfo(readBuffer);
}
}
public class MyAppSession : AppSession<MyAppSession, MyRequestInfo>
{
}
public class MyAppServer : AppServer<MyAppSession, MyRequestInfo>
{
public MyAppServer()
: base(new DefaultReceiveFilterFactory<MyReceiveFilter, MyRequestInfo>()) //使用默认的接受过滤器工厂 (DefaultReceiveFilterFactory)
{
}
}
以上是关于SuperSocket笔记的主要内容,如果未能解决你的问题,请参考以下文章