예제 #1
0
        void sendEchoMessage(TransportProtocol protocol)
        {
            FunapiSession.Transport transport = session_.GetTransport(protocol);
            if (transport == null)
            {
                FunDebug.LogWarning("sendEchoMessage - transport is null.");
                return;
            }

            ++echo_id_;

            if (transport.encoding == FunEncoding.kJson)
            {
                Dictionary <string, object> message = new Dictionary <string, object>();
                message["message"] = string.Format("[{0}] echo message ({1})", client_id_, echo_id_);
                session_.SendMessage("echo", message, protocol);
            }
            else if (transport.encoding == FunEncoding.kProtobuf)
            {
                PbufEchoMessage echo = new PbufEchoMessage();
                echo.msg = string.Format("[{0}] echo message ({1})", client_id_, echo_id_);
                FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
                session_.SendMessage("pbuf_echo", message, protocol);
            }
        }
    public void OnButtonSendEcho()
    {
        if (session == null)
        {
            return;
        }

        FunapiSession.Transport transport = session.GetTransport(info.protocol);
        if (transport == null)
        {
            FunDebug.LogWarning("sendEchoMessage - transport is null.");
            return;
        }

        if (transport.encoding == FunEncoding.kJson)
        {
            Dictionary <string, object> message = new Dictionary <string, object>();
            message["message"] = string.Format("[{0}] hello", transport.str_protocol);
            session.SendMessage("echo", message, info.protocol);
        }
        else if (transport.encoding == FunEncoding.kProtobuf)
        {
            PbufEchoMessage echo = new PbufEchoMessage();
            echo.msg = string.Format("[{0}] hello", transport.str_protocol);
            FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
            session.SendMessage("pbuf_echo", message, info.protocol);
        }
    }
        public void sendEchoMessage(TransportProtocol protocol = TransportProtocol.kDefault)
        {
            if (!session_.Connected && !session_.ReliableSession)
            {
                FunDebug.Log("You should connect first.");
                return;
            }

            if (encoding_ == FunEncoding.kJson)
            {
                // In this example, we are using Dictionary<string, object>.
                // But you can use your preferred Json implementation (e.g., Json.net) instead of Dictionary,
                // by changing FunapiMessage.JsonHelper property.
                Dictionary <string, object> message = new Dictionary <string, object>();
                message["message"] = string.Format("[{0}] hello json", protocol.ToString().Substring(1).ToLower());
                session_.SendMessage("echo", message, protocol);
            }
            else if (encoding_ == FunEncoding.kProtobuf)
            {
                PbufEchoMessage echo = new PbufEchoMessage();
                echo.msg = string.Format("[{0}] hello proto", protocol.ToString().Substring(1).ToLower());
                FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
                session_.SendMessage(MessageType.pbuf_echo, message, protocol);
            }
        }
예제 #4
0
        void onReceivedMessage(string type, object message)
        {
            if (type == "echo" || type == "pbuf_echo")
            {
                --sending_count_;
                if (sending_count_ <= 0)
                {
                    is_done_ = true;
                }
            }

            if (type == "echo")
            {
                Dictionary <string, object> json = message as Dictionary <string, object>;
                FunDebug.Log("[{0}] received: {1} (left:{2})", client_id_, json["message"] as string, sending_count_);
            }
            else if (type == "pbuf_echo")
            {
                FunMessage msg = message as FunMessage;
                object     obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_echo);
                if (obj == null)
                {
                    return;
                }

                PbufEchoMessage echo = obj as PbufEchoMessage;
                FunDebug.Log("[{0}] received: {1} (left:{2})", client_id_, echo.msg, sending_count_);
            }
        }
예제 #5
0
 void onReceivedMessage(string type, object message)
 {
     if (type == "echo")
     {
         FunDebug.Assert(message is Dictionary <string, object>);
         Dictionary <string, object> json = message as Dictionary <string, object>;
         FunDebug.Log("Received an echo message: {0}", json["message"]);
     }
     else if (type == "pbuf_echo")
     {
         FunMessage      msg  = message as FunMessage;
         PbufEchoMessage echo = FunapiMessage.GetMessage <PbufEchoMessage>(msg, MessageType.pbuf_echo);
         FunDebug.Log("Received an echo message: {0}", echo.msg);
     }
 }
        void onEchoWithProtobuf(object message)
        {
            FunDebug.Assert(message is FunMessage);
            FunMessage msg = message as FunMessage;
            object     obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_echo);

            if (obj == null)
            {
                return;
            }

            PbufEchoMessage echo = obj as PbufEchoMessage;

            FunDebug.Log("Received an echo message: {0}", echo.msg);
        }
예제 #7
0
 public void SendMessage(TransportProtocol protocol, string message)
 {
     if (protocol == TransportProtocol.kTcp)
     {
         PbufEchoMessage echo = new PbufEchoMessage();
         echo.msg = message;
         FunMessage fmsg = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
         session_.SendMessage(MessageType.pbuf_echo, fmsg, protocol);
     }
     else
     {
         Dictionary <string, object> echo = new Dictionary <string, object>();
         echo["message"] = message;
         session_.SendMessage("echo", echo, protocol);
     }
 }
예제 #8
0
        public void SendEcho()
        {
            if (tcp_count_ < kMaxMessageCount)
            {
                PbufEchoMessage echo = new PbufEchoMessage();
                echo.msg = string.Format("{0} message from tcp {1}", tcp_count_, index_.ToString());
                FunMessage msg = network_.CreateFunMessage(echo, MessageType.pbuf_echo);
                network_.SendMessage(MessageType.pbuf_echo, msg);
            }

            if (http_count_ < kMaxMessageCount)
            {
                Dictionary <string, object> msg = new Dictionary <string, object>();
                msg["message"] = string.Format("{0} message from http {1}", http_count_, index_.ToString());
                network_.SendMessage("echo", msg);
            }

            ++pending_count_;
        }
예제 #9
0
        void onReceivedMessage(string type, object message)
        {
            if (type == "echo")
            {
                Dictionary <string, object> json = message as Dictionary <string, object>;
                FunDebug.Log("[{0}] received: {1}", client_id, json["message"] as string);
            }
            else if (type == "pbuf_echo")
            {
                FunMessage msg = message as FunMessage;
                object     obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_echo);
                if (obj == null)
                {
                    return;
                }

                PbufEchoMessage echo = obj as PbufEchoMessage;
                FunDebug.Log("[{0}] received: {1}", client_id, echo.msg);
            }
        }
예제 #10
0
        void onReceivedMessage(string type, object message)
        {
            if (type == "echo")
            {
                Dictionary <string, object> json = message as Dictionary <string, object>;
                string echo_msg = json["message"] as string;
                FunDebug.Log("[{0}:{2}] {1}", id_, echo_msg, ++message_number_);
            }
            else if (type == "pbuf_echo")
            {
                FunMessage msg = message as FunMessage;
                object     obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_echo);
                if (obj == null)
                {
                    return;
                }

                PbufEchoMessage echo = obj as PbufEchoMessage;
                FunDebug.Log("[{0}:{2}] {1}", id_, echo.msg, ++message_number_);
            }
        }
예제 #11
0
    void sendEcho(TransportProtocol protocol)
    {
        FunapiSession.Transport transport = session.GetTransport(protocol);
        if (transport == null)
        {
            return;
        }

        if (transport.encoding == FunEncoding.kJson)
        {
            Dictionary <string, object> message = new Dictionary <string, object>();
            message["message"] = string.Format("[{0}] hello", transport.str_protocol);
            session.SendMessage("echo", message, protocol);
        }
        else if (transport.encoding == FunEncoding.kProtobuf)
        {
            PbufEchoMessage echo = new PbufEchoMessage();
            echo.msg = string.Format("[{0}] hello", transport.str_protocol);
            FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
            session.SendMessage("pbuf_echo", message, protocol);
        }
    }
예제 #12
0
        public void SendEcho()
        {
            if (tcp_count_ < kMaxMessageCount)
            {
                PbufEchoMessage echo = new PbufEchoMessage();
                echo.msg = string.Format("{0} message from tcp {1}", tcp_count_, index_.ToString());
                FunMessage msg = network_.CreateFunMessage(echo, MessageType.pbuf_echo);
                network_.SendMessage(MessageType.pbuf_echo, msg);
            }

            if (http_count_ < kMaxMessageCount)
            {
                Dictionary<string, object> msg = new Dictionary<string, object>();
                msg["message"] = string.Format("{0} message from http {1}", http_count_, index_.ToString());
                network_.SendMessage("echo", msg);
             }

            ++pending_count_;
        }
    private void SendEchoMessage ()
    {
        if (network_.Started == false && !network_.SessionReliability)
        {
            DebugUtils.Log("You should connect first.");
        }
        else
        {
            FunEncoding encoding = network_.GetEncoding(network_.GetDefaultProtocol());
            if (encoding == FunEncoding.kNone)
            {
                DebugUtils.Log("You should attach transport first.");
                return;
            }

            if (encoding == FunEncoding.kProtobuf)
            {
                PbufEchoMessage echo = new PbufEchoMessage();
                echo.msg = "hello proto";
                FunMessage message = network_.CreateFunMessage(echo, MessageType.pbuf_echo);
                network_.SendMessage(MessageType.pbuf_echo, message);
            }
            if (encoding == FunEncoding.kJson)
            {
                // In this example, we are using Dictionary<string, object>.
                // But you can use your preferred Json implementation (e.g., Json.net) instead of Dictionary,
                // by changing JsonHelper member in FunapiTransport.
                // Please refer to comments inside Connect() function.
                Dictionary<string, object> message = new Dictionary<string, object>();
                message["message"] = "hello world";
                network_.SendMessage("echo", message);
            }
        }
    }