Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            _ = new PerformanceCounterListener();

            IUdpBootstrap bootstrap = UdpFactory.Bootstrap();

            bootstrap.ConfigurationGlobalOptions(options => { });
            bootstrap.ConfigurationGlobalFilter((pipeline) =>
            {
                pipeline.Add(new UdpFilter_2());
            });
            await bootstrap.BuildAsync();

            IUdpChannel s_channel = await bootstrap.CreateChannelAsync();

            await s_channel.StartAsync(s_p);

            IUdpChannel c_channel = await bootstrap.CreateChannelAsync();

            await c_channel.StartAsync(c_p);

            int count = 0;

            byte[] com        = System.Text.Encoding.UTF8.GetBytes("send::::::::");
            byte[] countBytes = System.Text.Encoding.UTF8.GetBytes($"{count}___1");
            while (true)
            {
                string str = Console.ReadLine();
                if (str == "")
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        M.session.Write(Program.s_p, com);
                        M.session.Write(Program.s_p, countBytes);
                        await M.session.FlushAsync();
                    }

                    count++;
                    //for (int i = 1; i <= 100; i++)
                    //{
                    //    for (int j = 1; j <= 5; j++)
                    //    {
                    //        string com = $"{count}____{i}______{j}";
                    //        var bytes = System.Text.Encoding.UTF8.GetBytes(com);
                    //        M.session.Write(Program.s_p, bytes);
                    //    }

                    //    await M.session.FlushAsync();
                    //}
                }
                else if (str == "c")
                {
                    await M.session.CloseAsync();
                }
                else if (str == "s")
                {
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private void ReceiverListener()
        {
            while (true)
            {
                if (_isAlive)
                {
                    try
                    {
                        IPEndPoint rxEndPoint = null;

                        using (var _client = UdpFactory.CreateUdpRxClient(_port, ref rxEndPoint))
                        {
                            var receivedResults = _client.Receive(ref rxEndPoint);

                            var result = new RxObject()
                            {
                                Buffer        = receivedResults,
                                Date          = DateTime.Now,
                                Enabled       = true,
                                Ip            = rxEndPoint.Address.ToString(),
                                Port          = rxEndPoint.Port,
                                ProcessorType = typeof(P)
                            };

                            _rxProcessor.Add(result);

                            _consoleLog.Debug($"RX | IP: {result.Ip} | {result.Date.ToString()} | port: {result.Port} | data: {BitConverter.ToString(result.Buffer)}");
                        }
                    }
                    catch (SocketException ex)
                    {
                        _log.Error(ex);
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex);
                    }
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private void Send(TxObject tx)
        {
            try
            {
                IPEndPoint endPoint = null;

                using (var client = UdpFactory.CreateUdpRxClient(tx.Port, ref endPoint))
                {
                    endPoint = new IPEndPoint(IPAddress.Parse(tx.Ip), tx.Port);

                    client.Send(tx.Buffer, tx.Buffer.Length, endPoint);

                    Thread.Sleep(tx.Buffer.Length * 50);

                    _consoleLog.Warn($"TX | IP: {tx.Ip} | {tx.Date.ToString()} | port: {tx.Port} | data: {BitConverter.ToString(tx.Buffer)}");
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }
Ejemplo n.º 4
0
 public KcpBootstrap()
 {
     this.udpBootstrap = UdpFactory.Bootstrap();
     this.udpBootstrap.ConfigurationGlobalOptions(this.OnConfigurationOptions);
 }