Пример #1
0
    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);
            }
        }
    }
Пример #2
0
    private void OnMaintenanceMessage(string msg_type, object body)
    {
        FunEncoding encoding = network_.GetEncoding(network_.GetDefaultProtocol());

        if (encoding == FunEncoding.kNone)
        {
            DebugUtils.Log("Can't find a FunEncoding type for maintenance message.");
            return;
        }

        if (encoding == FunEncoding.kProtobuf)
        {
            FunMessage msg = body as FunMessage;
            object     obj = network_.GetMessage(msg, MessageType.pbuf_maintenance);
            if (obj == null)
            {
                return;
            }

            MaintenanceMessage maintenance = obj as MaintenanceMessage;
            DebugUtils.Log("Maintenance message\nstart: {0}\nend: {1}\nmessage: {2}",
                           maintenance.date_start, maintenance.date_end, maintenance.messages);
        }
        else if (encoding == FunEncoding.kJson)
        {
            DebugUtils.Assert(body is Dictionary <string, object>);
            Dictionary <string, object> msg = body as Dictionary <string, object>;
            DebugUtils.Log("Maintenance message\nstart: {0}\nend: {1}\nmessage: {2}",
                           msg["date_start"], msg["date_end"], msg["messages"]);
        }
    }
Пример #3
0
 public FunapiChatClient(FunapiSession session, FunEncoding encoding)
     : base(session, encoding)
 {
     JoinedCallback += onUserJoined;
     LeftCallback   += onUserLeft;
     ErrorCallback  += onError;
 }
        public byte[] GetBytes(FunEncoding encoding)
        {
            byte[] buffer = null;

            if (encoding == FunEncoding.kJson)
            {
                if (message == null)
                {
                    buffer = new byte[0];
                }
                else
                {
                    string str = json_helper_.Serialize(message);
                    buffer = System.Text.Encoding.UTF8.GetBytes(str);
                }
            }
            else
            {
                MemoryStream stream = new MemoryStream();
                serializer_.Serialize(stream, message);

                buffer = new byte[stream.Length];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(buffer, 0, buffer.Length);
            }

            return(buffer);
        }
        public FunapiMulticastClient(FunapiNetwork network, FunEncoding encoding)
        {
            DebugUtils.Assert(network != null);
            network_ = network;
            encoding_ = encoding;

            network_.RegisterHandlerWithProtocol(kMulticastMsgType, TransportProtocol.kTcp, OnReceived);
        }
        public FunapiMulticastClient(FunapiNetwork network, FunEncoding encoding)
        {
            DebugUtils.Assert(network != null);
            network_  = network;
            encoding_ = encoding;

            network_.RegisterHandlerWithProtocol(kMulticastMsgType, TransportProtocol.kTcp, OnReceived);
        }
Пример #7
0
        public FunapiMulticastClient(FunapiSession session, FunEncoding encoding)
        {
            FunDebug.Assert(session != null);

            session_  = session;
            encoding_ = encoding;

            session_.MulticastMessageCallback += onReceived;
        }
Пример #8
0
        public void Connect(string hostname_or_ip, ushort port, FunEncoding encoding, bool session_reliability)
        {
            // TODO(dkmoon): currenlty only Protobuf is supported.
            DebugUtils.Assert(encoding == FunEncoding.kProtobuf);

            // Discards previous instance, if any, and creates a brand new instance.
            multicasting_ = new FunapiMulticastClient (encoding);
            multicasting_.Connect(hostname_or_ip, port, session_reliability);
        }
        public FunapiMulticast(FunapiSession session, FunEncoding encoding, TransportProtocol protocol = TransportProtocol.kDefault)
        {
            FunDebug.Assert(session != null);

            session_  = session;
            encoding_ = encoding;
            protocol_ = protocol;

            session_.MulticastMessageCallback += onReceivedMessage;
        }
Пример #10
0
    int getType(FunEncoding value)
    {
        if (value == FunEncoding.kJson)
        {
            return(1);
        }
        else if (value == FunEncoding.kProtobuf)
        {
            return(2);
        }

        return(0);
    }
Пример #11
0
        public override IEnumerator Start(params object[] param)
        {
            // MulticastClient
            FunEncoding encoding = (FunEncoding)param[1];

            multicast_        = new FunapiMulticastClient((FunapiSession)param[0], encoding);
            multicast_.sender = "player_" + UnityEngine.Random.Range(1, 100);

            multicast_.ChannelListCallback += delegate(object channel_list) {
                onMulticastChannelList(encoding, channel_list);
            };
            multicast_.JoinedCallback += delegate(string channel_id, string sender) {
                FunDebug.DebugLog("JoinedCallback called. player:{0}", sender);
            };
            multicast_.LeftCallback += delegate(string channel_id, string sender) {
                FunDebug.DebugLog("LeftCallback called. player:{0}", sender);
            };
            multicast_.ErrorCallback += onMulticastError;

            // Getting channel list
            multicast_.RequestChannelList();
            yield return(new WaitForSeconds(0.1f));

            // Join the channel
            multicast_.JoinChannel(kChannelName, onMulticastChannelReceived);
            yield return(new WaitForSeconds(0.1f));

            // Send messages
            int sendingCount = (int)param[2];

            for (int i = 0; i < sendingCount; ++i)
            {
                sendMulticastMessage();
                yield return(new WaitForSeconds(0.1f));
            }

            // Getting channel list
            multicast_.RequestChannelList();
            yield return(new WaitForSeconds(0.1f));

            // Leave the channel
            multicast_.LeaveChannel(kChannelName);
            yield return(new WaitForSeconds(0.2f));

            multicast_.Clear();
            multicast_ = null;

            OnFinished();
        }
Пример #12
0
        public static object Deserialize(ArraySegment <byte> buffer, FunEncoding encoding)
        {
            if (encoding == FunEncoding.kJson)
            {
                string str = System.Text.Encoding.UTF8.GetString(buffer.Array, buffer.Offset, buffer.Count);
                //FunDebug.DebugLog("Parsed json: {0}", str);
                return(json_helper_.Deserialize(str));
            }
            else if (encoding == FunEncoding.kProtobuf)
            {
                MemoryStream stream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count, false);
                return(serializer_.Deserialize(stream, null, funmsg_type_));
            }

            return(null);
        }
Пример #13
0
        public void Connect(TransportProtocol protocol, FunEncoding encoding)
        {
            if (session == null)
            {
                SessionOption option = new SessionOption();
                option.sessionReliability    = false;
                option.sendSessionIdOnlyOnce = false;

                session = FunapiSession.Create(address, option);
                session.SessionEventCallback    += onSessionEvent;
                session.TransportEventCallback  += onTransportEvent;
                session.TransportErrorCallback  += onTransportError;
                session.ReceivedMessageCallback += onReceivedMessage;
            }

            session.Connect(protocol, encoding, getPort(protocol, encoding));
        }
Пример #14
0
    ushort getPort(TransportProtocol protocol, FunEncoding encoding)
    {
        ushort port = 0;

        if (protocol == TransportProtocol.kTcp)
        {
            port = (ushort)(encoding == FunEncoding.kJson ? 8012 : 8022);
        }
        else if (protocol == TransportProtocol.kUdp)
        {
            port = (ushort)(encoding == FunEncoding.kJson ? 8013 : 8023);
        }
        else if (protocol == TransportProtocol.kHttp)
        {
            port = (ushort)(encoding == FunEncoding.kJson ? 8018 : 8028);
        }

        return(port);
    }
Пример #15
0
    static void onMulticastChannelList(FunEncoding encoding, object channel_list)
    {
        if (encoding == FunEncoding.kJson)
        {
            List <object> list = channel_list as List <object>;
            if (list.Count <= 0)
            {
                FunDebug.Log("[Channel List] There are no channels.");
                return;
            }

            StringBuilder data = new StringBuilder();
            data.Append("[Channel List]\n");
            foreach (Dictionary <string, object> info in list)
            {
                data.AppendFormat("name:{0} members:{1}", info["_name"], info["_members"]);
                data.AppendLine();
            }
            FunDebug.Log(data.ToString());
        }
        else
        {
            List <FunMulticastChannelListMessage> list = channel_list as List <FunMulticastChannelListMessage>;
            if (list.Count <= 0)
            {
                FunDebug.Log("[Channel List] There are no channels.");
                return;
            }

            StringBuilder data = new StringBuilder();
            data.Append("[Channel List]\n");
            foreach (FunMulticastChannelListMessage info in list)
            {
                data.AppendFormat("name:{0} members:{1}", info.channel_name, info.num_members);
                data.AppendLine();
            }
            FunDebug.Log(data.ToString());
        }
    }
    void OnReceive(string type, object obj)
    {
        FunEncoding encoding = session_.GetEncoding();

        string result = "";

        if (type == "fb_authentication")
        {
            if (encoding == FunEncoding.kJson)
            {
                Dictionary <string, object> message = obj as Dictionary <string, object>;
                result = message["result"].ToString();
            }
            else if (encoding == FunEncoding.kProtobuf)
            {
                FunMessage         msg     = obj as FunMessage;
                PbufAnotherMessage message = FunapiMessage.GetMessage <PbufAnotherMessage>(msg, MessageType.pbuf_another);
                result = message.msg;
            }

            if (result == "ok")
            {
                logged_in_ = true;

                if (image_ != null && facebook_.MyPicture != null)
                {
                    image_.texture = facebook_.MyPicture;
                }

                setButtonState(true);
            }
            else
            {
                FunDebug.Log("facebook login authenticatiion failed.");

                facebook_.Logout();
            }
        }
    }
Пример #17
0
        public byte[] GetBytes(FunEncoding encoding)
        {
            if (encoding == FunEncoding.kJson)
            {
                if (message == null)
                {
                    return(new byte[0]);
                }
                else
                {
                    string str = json_helper_.Serialize(message);
                    return(System.Text.Encoding.UTF8.GetBytes(str));
                }
            }
            else if (encoding == FunEncoding.kProtobuf)
            {
                if (message == null)
                {
                    message = new FunMessage();
                }

                MemoryStream stream = new MemoryStream();
                serializer_.Serialize(stream, message);

                byte[] buffer = new byte[stream.Length];
                if (stream.Length > 0)
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    stream.Read(buffer, 0, buffer.Length);
                }

                return(buffer);
            }

            return(null);
        }
Пример #18
0
 public FunapiChatClient(FunapiNetwork network, FunEncoding encoding)
 {
     multicasting_ = new FunapiMulticastClient(network, encoding);
     encoding_     = encoding;
 }
 public FunapiMulticastClient(FunEncoding encoding)
 {
     encoding_ = encoding;
 }
Пример #20
0
        public static FunapiTransport CreateTransport(TransportProtocol protocol,
                                                      FunEncoding encoding      = FunEncoding.kJson,
                                                      EncryptionType encryption = EncryptionType.kDefaultEncryption)
        {
            if (data_ == null)
            {
                DebugUtils.Log("There's no config data. You should call FunapiConfig.Load first.");
                return(null);
            }

            string str_protocol;

            if (protocol == TransportProtocol.kTcp)
            {
                str_protocol = "tcp";
            }
            else if (protocol == TransportProtocol.kUdp)
            {
                str_protocol = "udp";
            }
            else if (protocol == TransportProtocol.kHttp)
            {
                str_protocol = "http";
            }
            else
            {
                DebugUtils.Log("CreateTransport - Invalid protocol. protocol: {0}", protocol);
                return(null);
            }

            string str_ip   = string.Format("{0}_server_ip", str_protocol);
            string str_port = string.Format("{0}_server_port", str_protocol);

            if (!data_.ContainsKey(str_ip) || !data_.ContainsKey(str_port))
            {
                DebugUtils.Log("CreateTransport - Can't find values with '{0}'", str_protocol);
                return(null);
            }

            string hostname_or_ip = data_[str_ip] as string;
            UInt16 port           = Convert.ToUInt16(data_[str_port]);

            if (hostname_or_ip.Length <= 0 || port == 0)
            {
                DebugUtils.Log("CreateTransport - Invalid value. ip:{0} port:{1} encoding:{2}",
                               hostname_or_ip, port, encoding);
                return(null);
            }

            if (protocol == TransportProtocol.kTcp)
            {
                FunapiTcpTransport transport = new FunapiTcpTransport(hostname_or_ip, port, encoding);

                if (data_.ContainsKey("disable_nagle"))
                {
                    transport.DisableNagle = (bool)data_["disable_nagle"];
                }

                if (encryption != EncryptionType.kDefaultEncryption)
                {
                    transport.SetEncryption(encryption);
                }

                return(transport);
            }
            else if (protocol == TransportProtocol.kUdp)
            {
                FunapiUdpTransport transport = new FunapiUdpTransport(hostname_or_ip, port, encoding);

                if (encryption != EncryptionType.kDefaultEncryption)
                {
                    transport.SetEncryption(encryption);
                }

                return(transport);
            }
            else if (protocol == TransportProtocol.kHttp)
            {
                bool with_https = false;
                if (data_.ContainsKey("http_with_secure"))
                {
                    with_https = (bool)data_["http_with_secure"];
                }

                FunapiHttpTransport transport = new FunapiHttpTransport(hostname_or_ip, port, with_https, encoding);

                if (encryption != EncryptionType.kDefaultEncryption)
                {
                    transport.SetEncryption(encryption);
                }

                return(transport);
            }

            return(null);
        }
 public FunapiChatClient(FunapiSession session, FunEncoding encoding, TransportProtocol protocol = TransportProtocol.kDefault)
     : base(session, encoding, protocol)
 {
 }
Пример #22
0
    private FunapiTransport GetNewTransport(TransportProtocol protocol)
    {
        FunapiTransport transport = null;
        FunEncoding     encoding  = with_protobuf_ ? FunEncoding.kProtobuf : FunEncoding.kJson;

        if (FunapiConfig.IsValid)
        {
            transport = FunapiConfig.CreateTransport(protocol, encoding);
        }

        if (transport == null)
        {
            if (protocol == TransportProtocol.kTcp)
            {
                transport = new FunapiTcpTransport(kServerIp, (ushort)(with_protobuf_ ? 8022 : 8012), encoding);
                transport.AutoReconnect = true;
                //transport.EnablePing = true;
                //transport.DisableNagle = true;

                //((FunapiTcpTransport)transport).SetEncryption(EncryptionType.kIFunEngine2Encryption);
            }
            else if (protocol == TransportProtocol.kUdp)
            {
                transport = new FunapiUdpTransport(kServerIp, (ushort)(with_protobuf_ ? 8023 : 8013), encoding);

                // Please set the same encryption type as the encryption type of server.
                //((FunapiUdpTransport)transport).SetEncryption(EncryptionType.kIFunEngine2Encryption);
            }
            else if (protocol == TransportProtocol.kHttp)
            {
                transport = new FunapiHttpTransport(kServerIp, (ushort)(with_protobuf_ ? 8028 : 8018), false, encoding);

                // Send messages using WWW class
                //((FunapiHttpTransport)transport).UseWWW = true;

                // Please set the same encryption type as the encryption type of server.
                //((FunapiHttpTransport)transport).SetEncryption(EncryptionType.kIFunEngine2Encryption);
            }
        }

        if (transport != null)
        {
            transport.StartedCallback += new TransportEventHandler(OnTransportStarted);
            transport.StoppedCallback += new TransportEventHandler(OnTransportClosed);
            transport.FailureCallback += new TransportEventHandler(OnTransportFailure);

            // Connect timeout.
            transport.ConnectTimeoutCallback += new TransportEventHandler(OnConnectTimeout);
            transport.ConnectTimeout          = 10f;

            // If you prefer use specific Json implementation other than Dictionary,
            // you need to register json accessors to handle the Json implementation before FunapiNetwork::Start().
            // E.g., transport.JsonHelper = new YourJsonAccessorClass

            // Adds extra server list
            // Use HostHttp for http transport.
            //transport.AddServerList(new List<HostAddr>{
            //    new HostAddr("127.0.0.1", 8012), new HostAddr("127.0.0.1", 8012),
            //    new HostAddr("127.0.0.1", 8013), new HostAddr("127.0.0.1", 8018)
            //});
        }

        return(transport);
    }
Пример #23
0
 public FunapiChatClient (FunapiNetwork network, FunEncoding encoding)
     : base(network, encoding)
 {
     JoinedCallback += new ChannelNotify(OnJoinedCallback);
     LeftCallback += new ChannelNotify(OnLeftCallback);
 }
Пример #24
0
 public FunapiChatClient(FunapiNetwork network, FunEncoding encoding)
 {
     multicasting_ = new FunapiMulticastClient(network, encoding);
     encoding_ = encoding;
 }
Пример #25
0
        public static FunapiTransport CreateTransport(TransportProtocol protocol,
                                                       FunEncoding encoding = FunEncoding.kJson,
                                                       EncryptionType encryption = EncryptionType.kDefaultEncryption)
        {
            if (data_ == null)
            {
                DebugUtils.Log("There's no config data. You should call FunapiConfig.Load first.");
                return null;
            }

            string str_protocol;
            if (protocol == TransportProtocol.kTcp)
                str_protocol = "tcp";
            else if (protocol == TransportProtocol.kUdp)
                str_protocol = "udp";
            else if (protocol == TransportProtocol.kHttp)
                str_protocol = "http";
            else
            {
                DebugUtils.Log("CreateTransport - Invalid protocol. protocol: {0}", protocol);
                return null;
            }

            string str_ip = string.Format("{0}_server_ip", str_protocol);
            string str_port = string.Format("{0}_server_port", str_protocol);
            if (!data_.ContainsKey(str_ip) || !data_.ContainsKey(str_port))
            {
                DebugUtils.Log("CreateTransport - Can't find values with '{0}'", str_protocol);
                return null;
            }

            string hostname_or_ip = data_[str_ip] as string;
            UInt16 port = Convert.ToUInt16(data_[str_port]);
            if (hostname_or_ip.Length <= 0 || port == 0)
            {
                DebugUtils.Log("CreateTransport - Invalid value. ip:{0} port:{1} encoding:{2}",
                               hostname_or_ip, port, encoding);
                return null;
            }

            if (protocol == TransportProtocol.kTcp)
            {
                FunapiTcpTransport transport = new FunapiTcpTransport(hostname_or_ip, port, encoding);

                if (data_.ContainsKey("disable_nagle"))
                    transport.DisableNagle = (bool)data_["disable_nagle"];

                if (encryption != EncryptionType.kDefaultEncryption)
                    transport.SetEncryption(encryption);

                return transport;
            }
            else if (protocol == TransportProtocol.kUdp)
            {
                FunapiUdpTransport transport = new FunapiUdpTransport(hostname_or_ip, port, encoding);

                if (encryption != EncryptionType.kDefaultEncryption)
                    transport.SetEncryption(encryption);

                return transport;
            }
            else if (protocol == TransportProtocol.kHttp)
            {
                bool with_https = false;
                if (data_.ContainsKey("http_with_secure"))
                    with_https = (bool)data_["http_with_secure"];

                FunapiHttpTransport transport = new FunapiHttpTransport(hostname_or_ip, port, with_https, encoding);

                if (encryption != EncryptionType.kDefaultEncryption)
                    transport.SetEncryption(encryption);

                return transport;
            }

            return null;
        }
Пример #26
0
        //---------------------------------------------------------------------
        // Connect-related functions
        //---------------------------------------------------------------------
        // For http transport, Pass a HostHttp instead of HostAddr.
        public bool Connect(TransportProtocol protocol, FunEncoding type, HostAddr addr)
        {
            FunapiTransport transport = GetTransport(protocol);
            if (transport == null)
            {
                DebugUtils.LogWarning("Connect - Can't find a {0} transport.", protocol);
                return false;
            }

            transport.Encoding = type;
            transport.ResetAddress(addr);

            transport.Connect();
            return true;
        }
        public FunapiTcpTransport(string hostname_or_ip, UInt16 port, FunEncoding type)
        {
            protocol_ = TransportProtocol.kTcp;
            str_protocol = "Tcp";
            DisableNagle = false;
            encoding_ = type;

            ip_list_.Add(hostname_or_ip, port);
            SetNextAddress();
        }
Пример #28
0
        public static FunapiMulticastClient CreateMulticasting(FunEncoding encoding, bool session_reliability)
        {
            if (data_ == null)
            {
                Debug.Log("There's no config data. You should call FunapiConfig.Load first.");
                return null;
            }

            string str_ip = "multicast_server_ip";
            string str_port = "multicast_server_port";
            if (!data_.ContainsKey(str_ip) || !data_.ContainsKey(str_port))
            {
                Debug.Log("CreateMulticasting - Can't find values for multicasting.");
                return null;
            }

            string hostname_or_ip = data_[str_ip] as string;
            UInt16 port = Convert.ToUInt16(data_[str_port]);
            if (hostname_or_ip.Length <= 0 || port == 0)
            {
                Debug.Log(String.Format("CreateMulticasting - Invalid value. ip:{0} port:{1} encoding:{2}",
                                        hostname_or_ip, port, encoding));
                return null;
            }

            FunapiMulticastClient multicast = new FunapiMulticastClient(encoding);
            multicast.Connect(hostname_or_ip, port, session_reliability);

            return multicast;
        }
        public FunapiUdpTransport(string hostname_or_ip, UInt16 port, FunEncoding type)
        {
            protocol_ = TransportProtocol.kUdp;
            str_protocol = "Udp";
            encoding_ = type;

            ip_list_.Add(hostname_or_ip, port);
            SetNextAddress();
        }
        public FunapiHttpTransport(string hostname_or_ip, UInt16 port, bool https, FunEncoding type)
        {
            protocol_ = TransportProtocol.kHttp;
            str_protocol = "Http";
            encoding_ = type;

            ip_list_.Add(hostname_or_ip, port, https);
            SetNextAddress();
        }
    public void OnGUI()
    {
        //----------------------------------------------------------------------------
        // FunapiNetwork test
        //----------------------------------------------------------------------------
        with_session_reliability_ = GUI.Toggle(new Rect(30, 5, 130, 20), with_session_reliability_, " session reliability");
        with_protobuf_ = GUI.Toggle(new Rect(180, 5, 150, 20), with_protobuf_, " google protocol buffer");

        GUI.Label(new Rect(30, 40, 300, 20), "[FunapiNetwork] - " + kServerIp);
        GUI.enabled = (network_ == null || !network_.Started);
        if (GUI.Button(new Rect(30, 60, 240, 40), "Connect (TCP)"))
        {
            Connect(TransportProtocol.kTcp);
        }
        if (GUI.Button(new Rect(30, 105, 240, 40), "Connect (UDP)"))
        {
            Connect(TransportProtocol.kUdp);
        }
        if (GUI.Button(new Rect(30, 150, 240, 40), "Connect (HTTP)"))
        {
            Connect(TransportProtocol.kHttp);
        }

        GUI.enabled = (network_ != null && network_.Connected);
        if (GUI.Button(new Rect(30, 195, 240, 40), "Disconnect"))
        {
            Disconnect();
        }

        if (GUI.Button(new Rect(30, 240, 240, 40), "Send a message"))
        {
            SendEchoMessage();
        }

        //----------------------------------------------------------------------------
        // Announcements test
        //----------------------------------------------------------------------------
        GUI.enabled = true;
        GUI.Label(new Rect(30, 300, 300, 20), string.Format("[Announcer] - {0}:{1}", kAnnouncementIp, kAnnouncementPort));
        if (GUI.Button(new Rect(30, 320, 240, 40), "Update announcements"))
        {
            if (announcement_ == null)
            {
                announcement_ = new FunapiAnnouncement();
                announcement_.ResultCallback += new FunapiAnnouncement.EventHandler(OnAnnouncementResult);

                string url = "";
                if (FunapiConfig.IsValid)
                    url = FunapiConfig.AnnouncementUrl;

                if (url.Length <= 0)
                    url = string.Format("http://{0}:{1}", kAnnouncementIp, kAnnouncementPort);

                if (url.Length <= 0)
                    return;

                announcement_.Init(url);
            }

            announcement_.UpdateList(5);
        }

        //----------------------------------------------------------------------------
        // Resource download test
        //----------------------------------------------------------------------------
        GUI.enabled = downloader_ == null;
        GUI.Label(new Rect(30, 380, 300, 20), string.Format("[Downloader] - {0}:{1}", kDownloadServerIp, kDownloadServerPort));
        if (GUI.Button(new Rect(30, 400, 240, 40), "Resource downloader (HTTP)"))
        {
            string download_url = "";

            if (FunapiConfig.IsValid) {
                FunapiConfig.GetDownloaderUrl(out download_url);
            }

            if (download_url == "") {
                download_url = string.Format("http://{0}:{1}", kDownloadServerIp, kDownloadServerPort);
            }

            downloader_ = new FunapiHttpDownloader();
            downloader_.VerifyCallback += new FunapiHttpDownloader.VerifyEventHandler(OnDownloadVerify);
            downloader_.ReadyCallback += new FunapiHttpDownloader.ReadyEventHandler(OnDownloadReady);
            downloader_.UpdateCallback += new FunapiHttpDownloader.UpdateEventHandler(OnDownloadUpdate);
            downloader_.FinishedCallback += new FunapiHttpDownloader.FinishEventHandler(OnDownloadFinished);
            downloader_.GetDownloadList(download_url, FunapiUtils.GetLocalDataPath);
        }

        //----------------------------------------------------------------------------
        // FunapiMulticasting test
        //----------------------------------------------------------------------------
        GUI.enabled = (multicast_ == null);
        GUI.Label(new Rect(280, 40, 300, 20), "[Muticasting]");
        string multicast_title = "Create 'multicast'";
        if (GUI.Button(new Rect(280, 60, 240, 40), multicast_title))
        {
            FunapiTransport transport = null;
            if (network_ == null || (transport = network_.GetTransport(TransportProtocol.kTcp)) == null) {
                DebugUtils.LogWarning("You should connect to tcp transport first.");
            }
            else {
                multicast_ = new FunapiMulticastClient(network_, transport.Encoding);
                multicast_encoding_ = transport.Encoding;
            }
        }

        GUI.enabled = (multicast_ != null && multicast_.Connected && !multicast_.InChannel(kMulticastTestChannel));
        multicast_title = "Join a channel";
        if (GUI.Button(new Rect(280, 105, 240, 40), multicast_title))
        {
            multicast_.JoinChannel(kMulticastTestChannel, OnMulticastChannelSignalled);
            DebugUtils.Log("Joining the multicast channel '{0}'", kMulticastTestChannel);
        }

        GUI.enabled = (multicast_ != null && multicast_.Connected && multicast_.InChannel(kMulticastTestChannel));
        multicast_title = "Send a message";
        if (GUI.Button(new Rect(280, 150, 240, 40), multicast_title))
        {
            if (multicast_encoding_ == FunEncoding.kJson)
            {
                Dictionary<string, object> mcast_msg = new Dictionary<string, object>();
                mcast_msg["_channel"] = kMulticastTestChannel;
                mcast_msg["_bounce"] = true;
                mcast_msg["message"] = "multicast test message";

                multicast_.SendToChannel(mcast_msg);
            }
            else
            {
                /*PbufHelloMessage hello_msg = new PbufHelloMessage();
                hello_msg.message = "multicast test message";

                FunMulticastMessage mcast_msg = new FunMulticastMessage();
                mcast_msg.channel = kMulticastTestChannel;
                mcast_msg.bounce = true;
                Extensible.AppendValue(mcast_msg, (int)MulticastMessageType.pbuf_hello, hello_msg);

                multicast_.SendToChannel(mcast_msg);*/
            }

            DebugUtils.Log("Sending a message to the multicast channel '{0}'", kMulticastTestChannel);
        }

        GUI.enabled = (multicast_ != null && multicast_.Connected && multicast_.InChannel(kMulticastTestChannel));
        multicast_title = "Leave a channel";
        if (GUI.Button(new Rect(280, 195, 240, 40), multicast_title))
        {
            multicast_.LeaveChannel(kMulticastTestChannel);
            DebugUtils.Log("Leaving the multicast channel '{0}'", kMulticastTestChannel);
        }

        GUI.Label(new Rect(280, 250, 300, 20), "[Multicast Chat]");
        GUI.enabled = (chat_ == null);
        string chat_title = "Create 'chat'";
        if (GUI.Button(new Rect(280, 270, 240, 40), chat_title))
        {
            FunapiTransport transport = null;
            if (network_ == null || (transport = network_.GetTransport(TransportProtocol.kTcp)) == null) {
                DebugUtils.LogWarning("You should connect to tcp transport first.");
            }
            else {
                chat_ = new FunapiChatClient(network_, transport.Encoding);
            }
        }

        GUI.enabled = (chat_ != null && chat_.Connected && !chat_.InChannel(kChatTestChannel));
        chat_title = "Join a channel";
        if (GUI.Button(new Rect(280, 315, 240, 40), chat_title))
        {
            chat_.JoinChannel(kChatTestChannel, kChatUserName, OnChatChannelReceived);
            DebugUtils.Log("Joining the chat channel '{0}'", kChatTestChannel);
        }

        GUI.enabled = (chat_ != null && chat_.Connected && chat_.InChannel(kChatTestChannel));
        chat_title = "Send a message";
        if (GUI.Button(new Rect(280, 360, 240, 40), chat_title))
        {
            chat_.SendText(kChatTestChannel, "hello world");

            DebugUtils.Log("Sending a message to the chat channel '{0}'", kChatTestChannel);
        }

        GUI.enabled = (chat_ != null && chat_.Connected && chat_.InChannel(kChatTestChannel));
        chat_title = "Leave a channel";
        if (GUI.Button(new Rect(280, 405, 240, 40), chat_title))
        {
            chat_.LeaveChannel(kChatTestChannel);
            DebugUtils.Log("Leaving the chat channel '{0}'", kChatTestChannel);
        }
    }
 int getType(FunEncoding value)
 {
     return(value == FunEncoding.kJson ? 0 : 1);
 }