Пример #1
0
        //static string host = "172.26.187.156";

        static async void AcceptLoop()
        {
            CancellationToken token = source.Token;

            while (!token.IsCancellationRequested)
            {
                Connection newconn = await listener.AcceptAsync(token);

                queue.Enqueue(newconn);
                _ = Task.Run(() =>
                {
                    while (true)
                    {
                        foreach (var newconn in queue)
                        {
                            try
                            {
                                byte[] data = newconn.Receive();
                                byte[] buff = new byte[800 * 1000];
                                Buffer.BlockCopy(data, 0, buff, 0, data.Length);
                                newconn.SendBytes(buff, SendOption.FragmentedReliable);
                            }
                            catch (Exception)
                            {
                            }
                            //Console.WriteLine(Encoding.UTF8.GetString(data));
                        }
                    }
                });
            }
        }