Exemplo n.º 1
0
    private void Start()
    {
        Subscribe(NetChannel.ConnectSucced, o =>
        {
            //
            isconnect = true;
            Loger.Log("ConnectSucced--->" + o[0]);
        });

        Subscribe(NetChannel.SendError, o =>
        {
            Loger.Log("SendError--->");
        });

        Subscribe(NetChannel.SendSucced, o =>
        {
            //
            byte[] bts   = (byte[])o[0];
            string words = Encoding.UTF8.GetString(bts);

            Loger.Log("SendSucced--->" + words);

            var text  = CloneText();
            text.text = words;
        });

        netChannel = new NetChannel("TestDemo");
        Connect.onClick.AddListener(() =>
        {
            //
            netChannel.Connect("127.0.0.1", 4567);
        });

        Send.onClick.AddListener(() =>
        {
            if (isconnect)
            {
                netChannel.Send(InputField.text);
            }
        });
    }
Exemplo n.º 2
0
        private void OnGUI()
        {
            if (GUILayout.Button("start sever", GUILayout.Width(400), GUILayout.Height(200)))
            {
                host = new ServerHost();

                host.Begin();
            }

            if (GUILayout.Button("Client A Connect", GUILayout.Width(400), GUILayout.Height(200)))
            {
                NetChannel client = new NetChannel("Client A");
                clients["Client A"] = client;
                client.Connect("127.0.0.1", 4567);
            }

            if (GUILayout.Button("Client A Send", GUILayout.Width(400), GUILayout.Height(200)))
            {
                clients["Client A"].Send("hello world");
                Loger.Color("Client A" + "say-->hello world", "yellow");
            }
        }