C2S.lua.txt 699 B

1234567891011121314151617181920212223242526
  1. local C2S = {}
  2. local function SendData(msgType, data)
  3. local jsonConvert = require("Base/json.lua")
  4. local message = jsonConvert:encode(data)
  5. if msgType ~= "HEARTBEAT" then
  6. local _, szTimeFormat = require("Base/Utils.lua"):TimeNow()
  7. print("----> C2S: message: szTimeFormat:", szTimeFormat, msgType, message)
  8. end
  9. local rpcId = CS.LuaSocketManager.Send(msgType, message)
  10. -- if rpcId == 0, there is a error on send. ignore this messsage.
  11. if rpcId ~= 0 then
  12. require("Network/NetworkQueue.lua"):PushUidOnSend(rpcId)
  13. end
  14. end
  15. function C2S:HeartBeat()
  16. local data = {
  17. ["ping"] = true,
  18. }
  19. SendData("HEARTBEAT", data)
  20. end
  21. return C2S