SendMessage() abstract private method

abstract private SendMessage ( FunapiMessage fun_msg ) : void
fun_msg FunapiMessage
return void
Esempio n. 1
0
        private void SendPingMessage(FunapiTransport transport)
        {
            long timestamp = DateTime.Now.Ticks;

            // Send response
            if (transport.Encoding == FunEncoding.kJson)
            {
                object msg = transport.JsonHelper.Deserialize("{}");
                transport.JsonHelper.SetStringField(msg, kMsgTypeBodyField, kClientPingMessageType);
                transport.JsonHelper.SetStringField(msg, kSessionIdBodyField, session_id_);
                transport.JsonHelper.SetIntegerField(msg, kPingTimestampField, timestamp);
                transport.SendMessage(new FunapiMessage(transport.Protocol, kClientPingMessageType, msg));
            }
            else if (transport.Encoding == FunEncoding.kProtobuf)
            {
                FunPingMessage ping = new FunPingMessage();
                ping.timestamp = timestamp;
                FunMessage msg = CreateFunMessage(ping, MessageType.cs_ping);
                msg.msgtype = kClientPingMessageType;
                msg.sid = session_id_;
                transport.SendMessage(new FunapiMessage(transport.Protocol, kClientPingMessageType, msg));
            }

            transport.PingWaitTime += transport.PingIntervalSeconds;
            DebugUtils.DebugLog("Send {0} ping - timestamp: {1}", transport.str_protocol, timestamp);
        }
Esempio n. 2
0
        private void OnServerPingMessage(FunapiTransport transport, object body)
        {
            if (transport == null)
            {
                DebugUtils.Log("OnServerPingMessage - transport is null.");
                return;
            }

            // Send response
            if (transport.Encoding == FunEncoding.kJson)
            {
                transport.JsonHelper.SetStringField(body, kMsgTypeBodyField, kServerPingMessageType);

                if (session_id_.Length > 0)
                    transport.JsonHelper.SetStringField(body, kSessionIdBodyField, session_id_);

                transport.SendMessage(new FunapiMessage(transport.Protocol,
                                                        kServerPingMessageType,
                                                        transport.JsonHelper.Clone(body)));
            }
            else if (transport.Encoding == FunEncoding.kProtobuf)
            {
                FunMessage msg = body as FunMessage;
                FunPingMessage obj = (FunPingMessage)GetMessage(msg, MessageType.cs_ping);
                if (obj == null)
                    return;

                FunPingMessage ping = new FunPingMessage();
                ping.timestamp = obj.timestamp;
                if (obj.data.Length > 0) {
                    ping.data = new byte[obj.data.Length];
                    Buffer.BlockCopy(ping.data, 0, obj.data, 0, obj.data.Length);
                }

                FunMessage send_msg = CreateFunMessage(ping, MessageType.cs_ping);
                send_msg.msgtype = msg.msgtype;
                send_msg.sid = session_id_;

                transport.SendMessage(new FunapiMessage(transport.Protocol, kServerPingMessageType, send_msg));
            }
        }
Esempio n. 3
0
        private void SendAck(FunapiTransport transport, UInt32 ack)
        {
            DebugUtils.Assert(session_reliability_);
            if (transport == null)
            {
                DebugUtils.Log("SendAck - transport is null.");
                return;
            }

            if (state_ == State.kStopped)
                return;

            DebugUtils.DebugLog("{0} send ack message - ack:{1}", transport.Protocol, ack);

            if (transport.Encoding == FunEncoding.kJson)
            {
                object ack_msg = transport.JsonHelper.Deserialize("{}");
                transport.JsonHelper.SetStringField(ack_msg, kSessionIdBodyField, session_id_);
                transport.JsonHelper.SetIntegerField(ack_msg, kAckNumberField, ack);
                transport.SendMessage(new FunapiMessage(transport.Protocol, "", ack_msg));
            }
            else if (transport.Encoding == FunEncoding.kProtobuf)
            {
                FunMessage ack_msg = new FunMessage();
                ack_msg.sid = session_id_;
                ack_msg.ack = ack;
                transport.SendMessage(new FunapiMessage(transport.Protocol, "", ack_msg));
            }
        }
Esempio n. 4
0
        private void OnAckReceived(FunapiTransport transport, UInt32 ack)
        {
            DebugUtils.Assert(session_reliability_);
            if (transport == null)
            {
                DebugUtils.LogError("OnAckReceived - transport is null.");
                return;
            }

            while (send_queue_.Count > 0)
            {
                UInt32 seq;
                FunapiMessage last_msg = send_queue_.Peek();
                if (transport.Encoding == FunEncoding.kJson)
                {
                    seq = (UInt32)transport.JsonHelper.GetIntegerField(last_msg.message, kSeqNumberField);
                }
                else if (transport.Encoding == FunEncoding.kProtobuf)
                {
                    seq = (last_msg.message as FunMessage).seq;
                }
                else
                {
                    DebugUtils.Assert(false);
                    seq = 0;
                }

                if (SeqLess(ack, seq))
                {
                    send_queue_.Dequeue();
                }
                else
                {
                    break;
                }
            }

            if (transport.state == FunapiTransport.State.kWaitForAck)
            {
                foreach (FunapiMessage msg in send_queue_)
                {
                    if (transport.Encoding == FunEncoding.kJson)
                    {
                        UInt32 seq = (UInt32)transport.JsonHelper.GetIntegerField(msg.message, kSeqNumberField);
                        DebugUtils.Assert(seq == ack || SeqLess(seq, ack));
                        transport.SendMessage(msg);
                    }
                    else if (transport.Encoding == FunEncoding.kProtobuf)
                    {
                        UInt32 seq = (msg.message as FunMessage).seq;
                        DebugUtils.Assert(seq == ack || SeqLess (seq, ack));
                        transport.SendMessage(msg);
                    }
                    else
                    {
                        DebugUtils.Assert(false);
                    }
                }

                SetTransportStarted(transport);
            }
        }