Exemplo n.º 1
0
        ///////////////////////////////// PONG //////////////////////////////////
        public void Ping(Action <ResponseEvent> callback)
        {
            PingTimer.Stop();
            if (string.IsNullOrEmpty(RequestHeader.AuthKey))
            {
                return;
            }
            var startTime = DateTime.Now;
            var routeId   = FrameSender?.RoomInfo?.RouteId ?? "";
            var conType   = this.Id == 1 ? ConnectionType.Relay : ConnectionType.Common;
            var body      = new HeartBeatReq {
                ConType = conType,
                RouteId = routeId
            };

            void PongResposne(bool send, DecodeRspResult result, Action <ResponseEvent> cb)
            {
                this.HandlePong(send, result, startTime);
            }

            var seq = this.Send(body.ToByteString(), (int)ProtoCmd.ECmdHeartBeatReq, PongResposne, callback);

            // if(this.Id == 1) Debugger.Log("send heartBeat: {0}", seq);
            CurrentSeq = seq;
            this.PongTimer.SetTimer(() => HandlePongTimeout(seq), this.Timeout);
        }
Exemplo n.º 2
0
        public static HeartBeatResp HeartBeat(HeartBeatReq req)
        {
            var ret = Class1.DoHttpRequest("/heart_beat/" + req.UserId, "GET", new Dictionary <string, string> {
                { "access_token", Class1.AccessToken }
            });
            var resp = JsonConvert.DeserializeObject <HeartBeatResp>(ret);

            return(resp);
        }
Exemplo n.º 3
0
        public static void ReqHeartBeat()
        {
            HeartBeatReq req = new HeartBeatReq();

            req.Header         = new Header();
            req.Header.ProtoID = ProtoID.ReqHeartBeat;

            ProtocolParser.SendMessage(req);
        }
Exemplo n.º 4
0
        public void Send()
        {
            HeartBeatReq req = new HeartBeatReq();

            req.Header          = new Header();
            req.Header.ProtoID  = ProtoID.ReqHeartBeat;
            req.Header.PlayerID = 1;
            sendProtocol.SendMessage(req);
        }
Exemplo n.º 5
0
		VitNetworkScript()
		{
			dispose = false;
			connected = false;

			m_heartSend = m_heartDelta;
			m_heartRev = 0.0f;

			m_heartBeatReq = new HeartBeatReq ();

//			VitProtobufDispatcher pDispatcher = VitProtobufDispatcher.Instance;
//			pDispatcher.RegisterMessageCallback<MsgHeartBeatRep>(parseHeartBeat, (int)ROOM_PROTOCOL_MSG_ID.ID_S2C_HEART_BEAT); 
		}
Exemplo n.º 6
0
        private void OnUpdate(float dt)
        {
            float current = SGFTime.GetTimeSinceStartup();

            if (current - m_lastHeartBeatTime > 5.0f)
            {
                m_lastHeartBeatTime = current;

                HeartBeatReq req = new HeartBeatReq();
                req.ping      = (ushort)m_ping;
                req.timestamp = (uint)TimeUtils.GetTotalMillisecondsSince1970();
                m_net.Send <HeartBeatReq, HeartBeatRsp>(ProtoCmd.HeartBeatReq, req, OnHeartBeatRsp, 15, OnHeartBeatError);
            }
        }
Exemplo n.º 7
0
        static void HeartBeat()
        {
            byte[]       data;
            HeartBeatReq heartBeatReq = new HeartBeatReq {
            };

            using (MemoryStream stream = new MemoryStream()) {
                heartBeatReq.WriteTo(stream);
                data = stream.ToArray();
            }
            while (true)
            {
                Thread.Sleep(2000);
                data = Utility.CombineCodeAndData(10102, new byte[] { });
                connection.Write(data);
            }
        }
Exemplo n.º 8
0
        private void OnHeartBeatReq(ISession session, uint index, HeartBeatReq req)
        {
            UserData ud = GetUserData(session.uid);

            if (ud != null)
            {
                ud.svrdata.lastHeartBeatTime = (uint)TimeUtils.GetTotalSecondsSince1970();
                session.ping = req.ping;

                HeartBeatRsp rsp = new HeartBeatRsp();
                rsp.ret       = ReturnCode.Success;
                rsp.timestamp = req.timestamp;
                m_net.Send(session, index, ProtoCmd.HeartBeatRsp, rsp);
            }
            else
            {
                Debuger.LogWarning("找不到Session 对应的UserData! session:{0}", session);
            }
        }
Exemplo n.º 9
0
        public void Encode(Remoting.Channel ch, object message, ByteArray output)
        {
            ByteArray  data      = new ByteArray();
            Dataoutput binOutput = new BinaryDataOutput(data);

            byte pType = 0, commpressed = 0;

            if (message is HandSankeReq)
            {
                pType       = Packet.FLAG_HANDSNAKE;
                commpressed = PacketHeader.UNCOMPRESSED;
                HandSankeReq req = message as HandSankeReq;
                req.SerializaTo(binOutput);
            }
            else if (message is HeartBeatReq)
            {
                pType       = Packet.FLAG_HEARTBEAT;
                commpressed = PacketHeader.UNCOMPRESSED;
                HeartBeatReq req = message as HeartBeatReq;
                req.SerializaTo(binOutput);
            }
            else if (message is Request)
            {
                pType       = Packet.FLAG_MESSAGE;
                commpressed = PacketHeader.UNCOMPRESSED;
                Request req = message as Request;
                binOutput.WriteInt(req.Id);
                binOutput.WriteByte(req.Type);
                binOutput.WriteInt(req.Sequence);
                binOutput.WriteBool(req.TwoWay);
                RequestArg content = (RequestArg)req.Content;
                content.SerializaTo(binOutput);
            }

            Dataoutput wholeOutput = new BinaryDataOutput(output);

            wholeOutput.WriteByte(MAGIC_HIGH);
            wholeOutput.WriteByte(MAGIC_LOW);
            wholeOutput.WriteByte(pType);
            wholeOutput.WriteByte(commpressed);
            wholeOutput.WriteInt(data.Length);
            output.WriteBytes(data.Bytes);
        }
Exemplo n.º 10
0
        static async Task Run()
        {
            var connection = new WebSocketsConnection();
            await connection.Connect();

            var readerTask = connection.ReadDataForever();

            byte[]   data, message;
            LoginReq loginReq = new LoginReq {
                Token = "eyJhbGciOiJIUzI1NiIsImtpZCI6ImtpZC1oZWFkZXIiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE1MzQ0MDk2MjMsInVpZCI6OTg2MzY0MzMxMjk0NzIxfQ.I9hZKcVzG9QLujrFoOjkCaWGwLrVZqI5f_rM-TC-QcE"
            };

            using (MemoryStream stream = new MemoryStream()) {
                loginReq.WriteTo(stream);
                message = stream.ToArray();
            }


            Console.WriteLine("edwin #26 {0}", BytesToString(CombineCodeAndData(10101, message)));

            await connection.WriteData(CombineCodeAndData(10101, message));



            Thread.Sleep(5000);


            HeartBeatReq heartBeatReq = new HeartBeatReq {
            };

            using (MemoryStream stream = new MemoryStream()) {
                heartBeatReq.WriteTo(stream);
                data = stream.ToArray();
            }


            while (true)
            {
                Thread.Sleep(5000);
                await connection.WriteData(data);
            }
        }
Exemplo n.º 11
0
 public override Task <HeartBeatAck> HeartBeat(HeartBeatReq request, ServerCallContext context)
 {
     loginMemberAdapter.UpdateMember(request.Header.PlayerID, DateTime.Now);
     return(Task.FromResult(new HeartBeatAck {
     }));
 }
Exemplo n.º 12
0
        public HeartBeatResp S1_009(HeartBeatReq heartBeatReq)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            try
            {
                string strhbReq = LogHelper.GetObjectMemberString(heartBeatReq);
                string strLog   = String.Format("Req:{0}:{{{1}}}", RequestIP, strhbReq);
                _log.Info(strLog);
            }
            catch (Exception ex)
            {
                string strLogErr = String.Format("Req Log Exception:{0}", ex.Message);
                _log.Error(strLogErr);
            }

            HeartBeatResp hbResponce = new HeartBeatResp();

            hbResponce.respCode = "9999";
            try
            {
                if (!String.IsNullOrEmpty(heartBeatReq.reqSysDate) && !String.IsNullOrEmpty(heartBeatReq.operationCode) && !String.IsNullOrEmpty(heartBeatReq.cityCode) && !String.IsNullOrEmpty(heartBeatReq.deviceId) && !String.IsNullOrEmpty(heartBeatReq.channelType))
                {
                    hbResponce.respCode = "0000";
                }
                else
                {
                    hbResponce.respCode = "0001";
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                if (null != ex.InnerException)
                {
                    _log.Error(ex.InnerException.Message);
                }
            }

            try
            {
                string strhbResp = LogHelper.GetObjectMemberString(hbResponce);
                string strLog    = String.Format("Resp:{{{0}}}", strhbResp);

                _log.Info(strLog);
            }
            catch (Exception ex)
            {
                string strLogErr = String.Format("Resp Log Exception:{0}", ex.Message);
                _log.Error(strLogErr);
            }

            sw.Stop();
            TimeSpan ts = sw.Elapsed;

            _log.Debug(ts.TotalMilliseconds);

            return(hbResponce);
        }