Text.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SuperSocket.SocketBase.Command;
  6. using SuperWebSocket.Protocol;
  7. namespace SuperWebSocket.Command
  8. {
  9. /// <summary>
  10. /// The command handling Text fragment
  11. /// </summary>
  12. /// <typeparam name="TWebSocketSession">The type of the web socket session.</typeparam>
  13. class Text<TWebSocketSession> : FragmentCommand<TWebSocketSession>
  14. where TWebSocketSession : WebSocketSession<TWebSocketSession>, new()
  15. {
  16. /// <summary>
  17. /// Gets the name.
  18. /// </summary>
  19. public override string Name
  20. {
  21. get
  22. {
  23. return OpCode.TextTag;
  24. }
  25. }
  26. /// <summary>
  27. /// Executes the command.
  28. /// </summary>
  29. /// <param name="session">The session.</param>
  30. /// <param name="requestInfo">The request info.</param>
  31. public override void ExecuteCommand(TWebSocketSession session, IWebSocketFragment requestInfo)
  32. {
  33. var frame = requestInfo as WebSocketDataFrame;
  34. if (!CheckFrame(frame))
  35. {
  36. session.Close();
  37. return;
  38. }
  39. if (frame.FIN)
  40. {
  41. if (session.Frames.Count > 0)
  42. {
  43. session.Close();
  44. return;
  45. }
  46. var text = GetWebSocketText(frame);
  47. session.AppServer.OnNewMessageReceived(session, text);
  48. }
  49. else
  50. {
  51. session.Frames.Add(frame);
  52. }
  53. }
  54. }
  55. }