SessionComponent.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using FL.Network;
  2. using XGame.Framework.Network;
  3. using XGame.Framework.Nodes;
  4. namespace FL.Nodes.Network
  5. {
  6. public class SessionComponent : NodeComponent, INetModuleListener
  7. {
  8. INetModule _netModule;
  9. public override void OnEnable(object intent)
  10. {
  11. _netModule = NetModule.Init(Context.Time, new FLMsgGenerator(), this);
  12. _netModule.Connect(new AddressInfo()
  13. {
  14. Address = "flkaifa.xmsgame.com",
  15. Port = 4001,
  16. ProtocolType = ProtocolType.WSS
  17. });
  18. }
  19. public override void OnDisable()
  20. {
  21. _netModule = null;
  22. NetModule.Dispose();
  23. }
  24. void INetModuleListener.OnHeartbeatTimeout()
  25. {
  26. throw new System.NotImplementedException();
  27. }
  28. void INetModuleListener.OnConnectStart()
  29. {
  30. XGame.Log.Info($"OnConnectStart");
  31. }
  32. void INetModuleListener.OnConnected()
  33. {
  34. EventSingle.Instance.Notify(EventDefine.ShowTips, "网络连接成功.");
  35. _netModule.StartHeartbeat();
  36. //NetModule.Request(new PlayerLoginRequest()
  37. //{
  38. // pid = "1",
  39. //});
  40. }
  41. void INetModuleListener.OnDisconnected()
  42. {
  43. XGame.Log.Info($"OnDisconnected");
  44. }
  45. void INetModuleListener.OnSessionError(SessionEventArgs args)
  46. {
  47. XGame.Log.Info($"OnSessionError Args:{args}");
  48. EventSingle.Instance.Notify(EventDefine.ShowTips, $"网络错误.Args:{args}");
  49. }
  50. void INetModuleListener.OnRequest(RequestEventArgs args)
  51. {
  52. XGame.Log.Info($"OnRequest Args:{args}");
  53. }
  54. void INetModuleListener.OnResponseSeqError(int seqId, int requestId, int responseId)
  55. {
  56. XGame.Log.Info($"OnResponseSeqError seqId:{seqId} requestId:{requestId} responseId:{responseId}");
  57. }
  58. void INetModuleListener.OnResponseFinish(ResponseEventArgs args)
  59. {
  60. XGame.Log.Info($"OnResponseFinish args:{args}");
  61. }
  62. }
  63. }