コード例 #1
0
ファイル: ClientKcp.cs プロジェクト: zhenyao2008/kcp_csserver
        private void button_init_Click(object sender, EventArgs e)
        {
            if (client != null)
            {
                client.Close();
            }
            client = new k.KcpClient("Test".ToCharArray().Select(a => (byte)a).ToArray(), 0, "kcppeer".ToCharArray().Select(a => (byte)a).ToArray());
            var arr = textBox_remote.Text.Split(":"[0]);

            remoteipep = new IPEndPoint(IPAddress.Parse(arr[0]), int.Parse(arr[1]));
            client.OnOperationResponse = (buf) =>
            {
                Console.WriteLine($"{nameof(CheckBigBBuff)}={CheckBigBBuff(buf)} size:{buf.Length} ");
            };
            client.OnConnected = (sid) =>
            {
                this.Invoke(
                    new Action(() =>
                {
                    this.Text = sid.ToString();
                })
                    );
            };

            client.Connect(remoteipep, true);
        }
コード例 #2
0
ファイル: ClientUdp.cs プロジェクト: zhenyao2008/kcp_csserver
        private void button_init_Click(object sender, EventArgs e)
        {
            if (client != null)
            {
                client.Close();
            }
            client = new k.UdpClient("Test".ToCharArray().Select(a => (byte)a).ToArray(), 0, "udppeer".ToCharArray().Select(a => (byte)a).ToArray());

            var arr = textBox_remote.Text.Split(":"[0]);

            remoteipep = new IPEndPoint(IPAddress.Parse(arr[0]), int.Parse(arr[1]));
            client.OnOperationResponse = (buf) =>
            {
                var i = BitConverter.ToInt64(buf, 0);
                //Console.Write($"rec:{i}");
                Task.Run(() =>
                {
                    var snd = i + 1;
                    Console.WriteLine($"udp snd:{snd}");
                    client.SendOperationRequest(BitConverter.GetBytes(snd));
                }
                         );
            };
            client.OnConnected = (sid) =>
            {
                this.Invoke(
                    new Action(() =>
                {
                    this.Text = sid.ToString();
                })
                    );
            };

            client.Connect(remoteipep, true);
        }