Exemplo n.º 1
0
        public UdpSession(UdpServer server, IPEndPoint remote)
        {
            Name      = server.Name;
            Stream    = new MemoryStream();
            StartTime = DateTime.Now;

            Server = server;
            Remote = new NetUri(NetType.Udp, remote);

            StatSend    = server.StatSend;
            StatReceive = server.StatReceive;

            // 检查并开启广播
            server.Client.CheckBroadcast(remote.Address);
        }
Exemplo n.º 2
0
        public UdpSession(UdpServer server, IPEndPoint remote)
        {
            Name      = server.Name;
            Stream    = new MemoryStream();
            StartTime = DateTime.Now;

            Server  = server;
            Remote  = new NetUri(NetType.Udp, remote);
            _Filter = remote;

            //StatSend = new Statistics();
            //StatReceive = new Statistics();
            StatSend    = server.StatSend;
            StatReceive = server.StatReceive;
        }
Exemplo n.º 3
0
        public UdpSession(UdpServer server, IPEndPoint remote)
        {
            Name = server.Name;
            Stream = new MemoryStream();
            StartTime = DateTime.Now;

            Server = server;
            Remote = new NetUri(NetType.Udp, remote);
            _Filter = remote;

            //StatSend = new Statistics();
            //StatReceive = new Statistics();
            StatSend = server.StatSend;
            StatReceive = server.StatReceive;
        }
Exemplo n.º 4
0
        private static void Test16()
        {
            for (int i = 0; i < 2000; i++)
            {
                var client = new UdpServer();
                Clients.Add(client);

                //client.Log = XTrace.Log;
                //client.LogSend = true;
                //client.LogReceive = true;
                client.Remote = "udp://192.168.0.12:89";
                client.Received += (s, e) => XTrace.WriteLine("{0} {1}", (s as UdpServer).Name, e.ToStr());
                //client.ReceiveAsync();
            }

            for (int i = 0; i < 100; i++)
            {
                foreach (var client in Clients)
                {
                    client.Send("Hello NewLife!");
                }
                Thread.Sleep(10000);
            }
        }
Exemplo n.º 5
0
        /// <summary>根据远程网络标识创建客户端</summary>
        /// <param name="remote"></param>
        /// <returns></returns>
        public static ISocketClient CreateRemote(this NetUri remote)
        {
            if (remote == null) throw new ArgumentNullException("remote");

            switch (remote.Type)
            {
                case NetType.Tcp:
                    var tcp = new TcpSession { Remote = remote };
                    return tcp;
                case NetType.Udp:
                    var udp = new UdpServer { Remote = remote, UseReceiveAsync = true };
                    return udp;
                default:
                    throw new NotSupportedException("不支持{0}协议".F(remote.Type));
            }
        }
Exemplo n.º 6
0
        /// <summary>根据本地网络标识创建客户端</summary>
        /// <param name="local"></param>
        /// <returns></returns>
        public static ISocketClient CreateClient(this NetUri local)
        {
            if (local == null) throw new ArgumentNullException("local");

            switch (local.Type)
            {
                case NetType.Tcp:
                    var tcp = new TcpSession { Local = local };
                    return tcp;
                case NetType.Udp:
                    var udp = new UdpServer { Local = local, UseReceiveAsync = true };
                    return udp;
                default:
                    throw new NotSupportedException("不支持{0}协议".F(local.Type));
            }
        }