Esempio n. 1
0
        void OnGUI()
        {
            int firstclient = server.connections.Count > 0 ? server.connections.First().Key : -1;

            GUILayout.BeginArea(new Rect(160, 5, 250, 400));
            GUILayout.Label("Server:");
            if (GUILayout.Button("Start"))
            {
                server.Start(Port);
            }
            if (GUILayout.Button("Send 0x01, 0x02 to " + firstclient))
            {
                server.Send(firstclient, new ArraySegment <byte>(new byte[] { 0x01, 0x02 }), KcpChannel.Reliable);
            }
            if (GUILayout.Button("Send 0x03, 0x04 to " + firstclient + " unreliable"))
            {
                server.Send(firstclient, new ArraySegment <byte>(new byte[] { 0x03, 0x04 }), KcpChannel.Unreliable);
            }
            if (GUILayout.Button("Disconnect connection " + firstclient))
            {
                server.Disconnect(firstclient);
            }
            if (GUILayout.Button("Stop"))
            {
                server.Stop();
            }
            GUILayout.EndArea();
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            KcpServer.CreateLink = (o) => { return(new KcpUser(o)); };
            var kcp = new KcpServer(8888);

            kcp.OpenHeart();
            RServer rs = new RServer();

            rs.name = "斗地主";
            rs.key  = "ert125dsaqwqf43bvrwurx24354tq245sd32dfkh348shdjfhs234sf5345";
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("193.112.70.170"), 6666);

            kcp.Send(KcpPack.PackObject <RServer>(ProCmd.Server, MessageType.Pro, rs), EnvelopeType.AesDataBuffer, endPoint);
            while (true)
            {
                var cmd = Console.ReadLine();
                if (cmd == "close" | cmd == "Close")
                {
                    break;
                }
            }
        }
Esempio n. 4
0
 void SendServerToClientBlocking(int connectionId, ArraySegment <byte> message, KcpChannel channel)
 {
     server.Send(connectionId, message, channel);
     UpdateSeveralTimes();
 }
Esempio n. 5
0
 public override bool ServerSend(int connectionId, int channelId, ArraySegment <byte> segment)
 {
     server.Send(connectionId, segment);
     return(true);
 }
Esempio n. 6
0
 private void Send(int connectionId, ArraySegment <byte> message, KcpChannel channel)
 {
     server.Send(connectionId, message, channel);
     Interlocked.Increment(ref benchmarkStatistics.MessagesServerSent);
 }