Example #1
0
        public async Task ClSendLoop(KcpClient cl)
        {
            var clid = clident++;
            await Task.Delay(200);

            while (true)
            {
                cl.Send(Encoding.Default.GetBytes($"Msg From:{clid},Time{DateTimeOffset.Now}").AsSpan());
                Console.WriteLine($"客户端{clid}消息发送,长度:{41}");
                await Task.Delay(2000);
            }
        }
Example #2
0
 void OnGUI()
 {
     GUILayout.BeginArea(new Rect(5, 5, 150, 400));
     GUILayout.Label("Client:");
     if (GUILayout.Button("Connect 127.0.0.1"))
     {
         client.Connect("127.0.0.1", Port, true, 10);
     }
     if (GUILayout.Button("Send 0x01, 0x02 reliable"))
     {
         client.Send(new ArraySegment <byte>(new byte[] { 0x01, 0x02 }), KcpChannel.Reliable);
     }
     if (GUILayout.Button("Send 0x03, 0x04 unreliable"))
     {
         client.Send(new ArraySegment <byte>(new byte[] { 0x03, 0x04 }), KcpChannel.Unreliable);
     }
     if (GUILayout.Button("Disconnect"))
     {
         client.Disconnect();
     }
     GUILayout.EndArea();
 }
        public static bool Send(int connectionID, ArraySegment <byte> segment, Source source = Source.Default, int channelId = 1)
        {
            if (source == Source.Default)
            {
                return(false);
            }

            if (source == Source.Server && IsServer)
            {
                switch (channelId)
                {
                case (int)UDPChannels.Unreliable:
                    server.Send(connectionID, segment, KcpChannel.Unreliable);
                    break;

                default:
                    server.Send(connectionID, segment, KcpChannel.Reliable);
                    break;
                }
                return(true);
            }

            if (source == Source.Client && IsClient)
            {
                switch (channelId)
                {
                case (int)UDPChannels.Unreliable:
                    client.Send(segment, KcpChannel.Unreliable);
                    break;

                default:
                    client.Send(segment, KcpChannel.Reliable);
                    break;
                }
                return(true);
            }

            return(false);
        }
Example #4
0
 void SendClientToServerBlocking(ArraySegment <byte> message, KcpChannel channel)
 {
     client.Send(message, channel);
     UpdateSeveralTimes();
 }
Example #5
0
 public override bool ClientSend(int channelId, ArraySegment <byte> segment)
 {
     client.Send(segment);
     return(true);
 }
Example #6
0
 void SendClientToServerBlocking(ArraySegment<byte> message)
 {
     client.Send(message);
     UpdateSeveralTimes();
 }