MessageReceiveFilter.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using CommonLang.ByteOrder;
  2. using CommonLang.Net;
  3. using SuperSocket.Facility.Protocol;
  4. using SuperSocket.SocketBase;
  5. using SuperSocket.SocketBase.Command;
  6. using SuperSocket.SocketBase.Protocol;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. namespace CommonServer.SSocket.SuperSocket
  12. {
  13. public class MessageReceiveFilterFactory : IReceiveFilterFactory<BinaryRequestInfo>
  14. {
  15. public MessageReceiveFilterFactory(INetPackageCodec codec)
  16. {
  17. }
  18. public IReceiveFilter<BinaryRequestInfo> CreateFilter(IAppServer appServer, IAppSession appSession, System.Net.IPEndPoint remoteEndPoint)
  19. {
  20. return new MessageReceiveFilter(appServer, appSession as Session);
  21. }
  22. }
  23. public class MessageReceiveFilter : FixedHeaderReceiveFilter<BinaryRequestInfo>
  24. {
  25. public MessageReceiveFilter(IAppServer appServer, Session appSession)
  26. : base(4)
  27. {
  28. }
  29. protected override int GetBodyLengthFromHeader(byte[] header, int offset, int length)
  30. {
  31. int pos = offset;
  32. int bodyLength = LittleEdian.GetS32(header, ref pos);
  33. return bodyLength;
  34. }
  35. protected override BinaryRequestInfo ResolveRequestInfo(ArraySegment<byte> header, byte[] bodyBuffer, int offset, int length)
  36. {
  37. byte[] bin = new byte[length];
  38. Buffer.BlockCopy(bodyBuffer, offset, bin, 0, length);
  39. return new BinaryRequestInfo("BinCommand", bin);
  40. }
  41. }
  42. }