当前位置: 首页>>代码示例>>C#>>正文


C# Net.EndPoint类代码示例

本文整理汇总了C#中System.Net.EndPoint的典型用法代码示例。如果您正苦于以下问题:C# EndPoint类的具体用法?C# EndPoint怎么用?C# EndPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EndPoint类属于System.Net命名空间,在下文中一共展示了EndPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TCPSocket

        public TCPSocket(Socket from, bool socket_listening)
        {
            sock = from;
            listening = socket_listening;

            if (socket_listening)
            {
                IPEndPoint tmp = (IPEndPoint)sock.LocalEndPoint;
                port = (ushort)tmp.Port;
                ep = tmp;
            }
            else
            {
                IPEndPoint tmp = (IPEndPoint)sock.RemoteEndPoint;
                port = (ushort)tmp.Port;
                ep = tmp;
            }

            if (sock.Blocking == false)
            {
                sock.Blocking = true;
            }

            sock.ReceiveBufferSize = 1024 * 64; // 64 kb
            sock.SendBufferSize = 1024 * 64; // 64 kb
        }
开发者ID:Reve,项目名称:EVESharp,代码行数:26,代码来源:TCPSocket.cs

示例2: GetRTO

 public TimeSpan GetRTO(EndPoint ep)
 {
     State state = GetState (ep, InvalidValue);
     if (state == null)
         return _defaultRTO;
     return new TimeSpan (Math.Max (_minRTO, state.RTO) * TimeSpan.TicksPerMillisecond);
 }
开发者ID:kazuki,项目名称:p2pncs,代码行数:7,代码来源:RFC2988BasedRTOCalculator.cs

示例3: UDPPacketBuffer

        public UDPPacketBuffer()
        {
            this.Data = new byte[BUFFER_SIZE];

            // this will be filled in by the call to udpSocket.BeginReceiveFrom
            RemoteEndPoint = (EndPoint)new IPEndPoint(IPAddress.Any, 0);
        }
开发者ID:kensniper,项目名称:castle-butcher,代码行数:7,代码来源:UDPPacketBuffer.cs

示例4: Test1

        protected void Test1(IDatagramEventSocket[] sockets, EndPoint[] endPoints)
        {
            byte[] sendData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
            int recvIdx = -1, recvSize = -1;
            byte[] recvData = null;
            AutoResetEvent done = new AutoResetEvent (false);

            for (int i = 0; i < sockets.Length; i++) {
                sockets[i].Bind (endPoints[i]);
                sockets[i].Received += new DatagramReceiveEventHandler (delegate (object sender, DatagramReceiveEventArgs e) {
                    recvIdx = Array.IndexOf<IDatagramEventSocket> (sockets, sender as IDatagramEventSocket);
                    recvSize = e.Size;
                    recvData = (byte[])e.Buffer.Clone ();
                    done.Set ();
                });
            }

            for (int i = 0; i < sockets.Length; i++) {
                for (int k = 0; k < endPoints.Length; k++) {
                    sockets[i].SendTo (sendData, endPoints[k]);
                    done.WaitOne ();
                    Array.Resize<byte> (ref recvData, recvSize);
                    string id = "#" + (i + 1).ToString () + "." + (k + 1).ToString ();
                    Assert.AreEqual (k, recvIdx, id + ".1");
                    Assert.AreEqual (sendData.Length, recvSize, id + ".2");
                    Assert.AreEqual (sendData, recvData, id + ".3");
                }
            }
        }
开发者ID:kazuki,项目名称:p2pncs,代码行数:29,代码来源:IDatagramEventSocketTest.cs

示例5: NetState

        internal NetState(EndPoint ep)
        {
            EndPoint = ep;

            AddClient(this);
            LogLine("Connected");
        }
开发者ID:stevenzeiler,项目名称:FeenPhone,代码行数:7,代码来源:NetState.cs

示例6: BeginReceiveAll

        public void BeginReceiveAll(byte[] buffer, int count, EndPoint remoteEndPoint)
        {
            ValidateTransferAllArguments(buffer, ref count);

            var transfered = 0;
            AsyncCallback callback = null;
            callback = result =>
            {
                var endPoint = result.AsyncState as EndPoint;
                if (endPoint == null)
                    return;

                var current = Socket.EndReceiveFrom(result, ref endPoint);
                if (current == 0)
                {
                    ReceiveCompleted?.Invoke(this, new TransferEventArgs(this, buffer, transfered, endPoint));
                    return;
                }

                transfered += current;
                if (transfered < current)
                    Socket.BeginReceiveFrom(buffer, transfered, count - transfered, SocketFlags.None, ref endPoint, callback, endPoint);
                else
                    ReceiveCompleted?.Invoke(this, new TransferEventArgs(this, buffer, transfered, endPoint));
            };

            Socket.BeginReceiveFrom(buffer, transfered, count - transfered, SocketFlags.None, ref remoteEndPoint, callback, remoteEndPoint);
        }
开发者ID:joelluijmes,项目名称:ManagedNetworking,代码行数:28,代码来源:UdpClient.Event.cs

示例7: EchoConnectionHandler

        public EchoConnectionHandler(EndPoint remote, IActorRef connection)
        {
            // we want to know when the connection dies (without using Tcp.ConnectionClosed)
            Context.Watch(connection);

            Receive<Tcp.Received>(received =>
            {
                var text = Encoding.UTF8.GetString(received.Data.ToArray()).Trim();
                Console.WriteLine("Received '{0}' from remote address [{1}]", text, remote);
                if (text == "exit")
                    Context.Stop(Self);
                else
                    Sender.Tell(Tcp.Write.Create(received.Data));
            });
            Receive<Tcp.ConnectionClosed>(closed =>
            {
                Console.WriteLine("Stopped, remote connection [{0}] closed", remote);
                Context.Stop(Self);
            });
            Receive<Terminated>(terminated =>
            {
                Console.WriteLine("Stopped, remote connection [{0}] died", remote);
                Context.Stop(Self);
            });
        }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:25,代码来源:Actors.cs

示例8: HandleFlood

        public bool HandleFlood(EndPoint id)
        {
            if (_floods.ContainsKey(id))
            {
                FloodCount counter = _floods[id];
                counter.PacketCount++;
                _floods[id] = counter;

                if (counter.StopWatch.ElapsedMilliseconds > _msecTime)
                {
                    _floods.Remove(id);
                }
                else
                {
                    _floods.Remove(id);
                    return false;
                }
            }
            else
            {
                FloodCount counter = new FloodCount();
                counter.PacketCount = 1;
                counter.StopWatch.Start();

                _floods.Add(id, counter);

            }

            return true;
        }
开发者ID:xNexus9,项目名称:tabula-rasa-server-emulator,代码行数:30,代码来源:FloodProtector.cs

示例9: Connect_Click

        private void Connect_Click(object sender, EventArgs e)
        {
            try
            {
                epLocal = new IPEndPoint(IPAddress.Parse(IPClient_1.Text), Convert.ToInt32(PortClient_1.Text));
                sck.Bind(epLocal);

                epRemote = new IPEndPoint(IPAddress.Parse(IPClient_2.Text), Convert.ToInt32(PortClient_2.Text));
                sck.Connect(epRemote);

                byte[] buffer = new byte[1500];
                sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);

                Connect.Enabled = false;
                Send.Enabled = true;
                Сondition.Text = "Подключено";
                tbSend.Focus();

                form1.Form1_IPClient_1 = IPClient_1.Text; form1.Form1_IPClient_2 = IPClient_2.Text;
                form1.Form1_PortClient_1 = PortClient_1.Text; form1.Form1_PortClient_2 = PortClient_2.Text;
                form1.Player1.Text = NameClient_1.Text; form1.Player2.Text = NameClient_2.Text;
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString());
                MessageBox.Show("Проблема с подключением, проверте: \r\n - верно ли внесены сетевые настройки игры;\r\n - отсутствует сетевое подключение;\r\n - Ваш противник покинул игру или неуспел подключится.", "Oшибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
            }
        }
开发者ID:IamRoman,项目名称:Ping_pong_Game,代码行数:28,代码来源:SettingsForm2.cs

示例10: ServerCounters

 internal ServerCounters(EndPoint endpoint)
 {
     this.EndPoint = endpoint;
     this.Interactive = new ConnectionCounters(ConnectionType.Interactive);
     this.Subscription = new ConnectionCounters(ConnectionType.Subscription);
     this.Other = new ConnectionCounters(ConnectionType.None);
 }
开发者ID:BiYiTuan,项目名称:StackExchange.Redis,代码行数:7,代码来源:ServerCounters.cs

示例11: Connect

        public void Connect(EndPoint endPoint)
        {
            byte[] data = new byte[1024];
            string input, stringData;
            int recv;
            Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            int sockopt = (int)server.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
            Console.WriteLine("Default timeout: {0}", sockopt);
            server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
            sockopt = (int)server.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
            Console.WriteLine("New timeout: {0}", sockopt);

            string welcome = "Hello, are you there?";
            data = Encoding.ASCII.GetBytes(welcome);
            server.SendTo(data, data.Length, SocketFlags.None, endPoint);

            data = new byte[1024];
            try
            {
                Console.WriteLine("Waiting from {0}:", endPoint.ToString());
                recv = server.ReceiveFrom(data, ref endPoint);
                Console.WriteLine("Message received from {0}:", endPoint.ToString());
                Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
            }
            catch (SocketException e)
            {
                if (e.SocketErrorCode == SocketError.HostUnreachable)
                    throw new Exception("CLOSED");
                throw new Exception("TIME_OUT");
            }
            Console.WriteLine("Stopping client");
            server.Close();
        }
开发者ID:rqx110,项目名称:NScanner,代码行数:33,代码来源:UdpConnectCall.cs

示例12: CreateMessagingSocket

 protected override void CreateMessagingSocket(int idx, SymmetricKey key, out IMessagingSocket socket, out EndPoint endPoint)
 {
     endPoint = new IPEndPoint (_adrsGen.Next (), 10000);
     VirtualDatagramEventSocket sock = new VirtualDatagramEventSocket (_net, ((IPEndPoint)endPoint).Address);
     sock.Bind (endPoint);
     socket = new VirtualMessagingSocket (sock, true, _interrupter, DefaultRTO, DefaultRetryCount, 1024, 1024);
 }
开发者ID:kazuki,项目名称:p2pncs,代码行数:7,代码来源:VirtualMessagingSocketTest.cs

示例13: Bind2

 public void Bind2(EndPoint ep)
 {
     if (ep == null)
         Bind(new IPEndPoint(IPAddress.Any, 0));
     else
         Bind(ep);
 }
开发者ID:Cyber-Forensic,项目名称:Potato,代码行数:7,代码来源:SocketEx.cs

示例14: SocketServer

		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="hostEndPoint">Identifies a Network resource that this server is listening on.</param>
		/// <param name="bufferSize">Size of the buffer to use when receiving data from a connected client.</param>
		/// <param name="clientReadTimeout">amount of time that the server will wait 
		/// for a client to send data before timing the client out.</param>
		/// <param name="clientSendTimeout">amount of time that the server will wait 
		/// for a client to receive data before timing the client out.</param>
		public SocketServer(EndPoint hostEndPoint, int bufferSize, TimeSpan clientReadTimeout, TimeSpan clientSendTimeout)
		{
			_hostEndPoint = hostEndPoint;
			_bufferSize = bufferSize;
			_clientReadTimeout = clientReadTimeout;
			_clientSendTimeout = clientSendTimeout;
		}
开发者ID:EquisoftDev,项目名称:EquisoftDev.github.io,代码行数:16,代码来源:SocketServer.cs

示例15: GetState

        State GetState(EndPoint ep, TimeSpan rtt)
        {
            if (_states == null) {
                lock (this) {
                    if (_state == null && !InvalidValue.Equals (rtt))
                        _state = new State ((int)rtt.TotalMilliseconds, _timerGranularity);
                    return _state;
                }
            }

            IPEndPoint ipep = ep as IPEndPoint;
            if (ipep == null)
                throw new ArgumentException ();

            State state;
            bool success;
            using (_lock.EnterReadLock ()) {
                success = _states.TryGetValue (ipep.Address, out state);
            }
            if (!success && !InvalidValue.Equals (rtt)) {
                using (_lock.EnterWriteLock ()) {
                    if (!_states.TryGetValue (ipep.Address, out state)) {
                        state = new State ((int)rtt.TotalMilliseconds, _timerGranularity);
                        _states.Add (ipep.Address, state);
                    }
                }
            }
            return state;
        }
开发者ID:kazuki,项目名称:p2pncs,代码行数:29,代码来源:RFC2988BasedRTOCalculator.cs


注:本文中的System.Net.EndPoint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。