SimpleMessageHandler.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using DotNetty.Transport.Channels;
  2. using System;
  3. using System.Collections.Concurrent;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace NettyClient
  10. {
  11. public class SimpleMessageHandler : ChannelHandlerAdapter
  12. {
  13. public SimpleMessageHandler() {
  14. }
  15. public IChannelHandlerContext context;
  16. public override void ChannelActive(IChannelHandlerContext context)
  17. {
  18. MessageBox.Show("connected");
  19. this.context = context;
  20. }
  21. public override void ChannelRead(IChannelHandlerContext context, object message)
  22. {
  23. }
  24. public override void ChannelReadComplete(IChannelHandlerContext context)
  25. {
  26. context.Flush();
  27. }
  28. public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
  29. {
  30. Console.WriteLine("Exception: " + exception);
  31. context.CloseAsync();
  32. }
  33. //public override void ChannelInactive(IChannelHandlerContext context)
  34. //{
  35. // base.ChannelInactive(context);
  36. // Console.WriteLine("1");
  37. //}
  38. //public override void ChannelUnregistered(IChannelHandlerContext context)
  39. //{
  40. // base.ChannelUnregistered(context);
  41. // Console.WriteLine("2");
  42. //}
  43. public override void HandlerRemoved(IChannelHandlerContext context)
  44. {
  45. base.HandlerRemoved(context);
  46. }
  47. //public void toString(Message msg)
  48. //{
  49. // MessageBox.Show("Received from server: cmd : " + msg.Cmd + ", taskId : " + msg.TaskId + ", content : " + msg.Content);
  50. //}
  51. }
  52. }