TcpServerCallbackImpl.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using CommonLang.Log;
  2. using CommonLang.Protocol;
  3. using CommonNetwork_ICE.Client;
  4. using CommonNetwork_ICE.Common;
  5. using CommonNetwork_ICE.Session;
  6. using CommonNetwork_ICE.Util;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. namespace CommonNetwork_ICE.handler
  12. {
  13. class TcpServerCallbackImpl : Slice.ServerCallbackDisp_
  14. {
  15. private static Logger log = LoggerFactory.GetLogger("TcpServerCallbackImpl");
  16. private IceClientNetSession session;
  17. private IceMessageCodec codec;
  18. public TcpServerCallbackImpl(IceMessageCodec codec, IceClientNetSession session)
  19. {
  20. this.codec = codec;
  21. this.session = session;
  22. }
  23. public override void ServerToClient(Slice.TransMessage message, Ice.Current current__)
  24. {
  25. // 数据解码
  26. IMessage imessage = null;
  27. try
  28. {
  29. codec.doDecode(message, out imessage);
  30. }
  31. catch (Exception e)
  32. {
  33. Env.ENV_ERR_CODE = Error.ERR_CODE_4;
  34. session.onException(e);
  35. return;
  36. }
  37. if (imessage == null)
  38. {
  39. return;
  40. }
  41. // 数据处理
  42. try
  43. {
  44. long startTickCount = Environment.TickCount;
  45. session.onReceive(imessage, message.length);
  46. long endTickCount = Environment.TickCount;
  47. long interval = endTickCount - startTickCount;
  48. if (interval > Env.MSG_PROC_TIME_OUT)
  49. {
  50. log.Info("客户端消息处理超时,用时【" + interval + "】,消息编号【" + imessage.GetType() + "】");
  51. }
  52. }
  53. catch (Exception e)
  54. {
  55. log.Error(e.Message);
  56. Env.ENV_ERR_CODE = Error.ERR_CODE_5;
  57. session.onException(e);
  58. }
  59. }
  60. }
  61. }