• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Net.EndPoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Socket

 Task<ActiveConnectResult> IActiveConnector.ActiveConnect(EndPoint targetEndPoint)
 {
     var taskSource = new TaskCompletionSource<ActiveConnectResult>();
     var socket = new Socket(targetEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     socket.BeginConnect(targetEndPoint, OnActiveConnectCallback, new ActiveConnectState(taskSource, socket));
     return taskSource.Task;
 }
开发者ID:haylax,项目名称:SuperSocket,代码行数:7,代码来源:AsyncSocketServer.cs


示例17: ConnectToServerWithTimeout

        /// <summary>
        /// This code is used to connect to a TCP socket with timeout option.
        /// </summary>
        /// <param name="endPoint">IP endpoint of remote server</param>
        /// <param name="timeoutMs">Timeout to wait until connect</param>
        /// <returns>Socket object connected to server</returns>
        public static Socket ConnectToServerWithTimeout(EndPoint endPoint, int timeoutMs)
        {
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                socket.Blocking = false;
                socket.Connect(endPoint);
                socket.Blocking = true;
                return socket;
            }
            catch (SocketException socketException)
            {
                if (socketException.ErrorCode != 10035)
                {
                    socket.Close();
                    throw;
                }

                if (!socket.Poll(timeoutMs * 1000, SelectMode.SelectWrite))
                {
                    socket.Close();
                    throw new NGRIDException("The host failed to connect. Timeout occured.");
                }

                socket.Blocking = true;
                return socket;
            }
        }
开发者ID:ashwinrath,项目名称:NGRID,代码行数:34,代码来源:GeneralHelper.cs


示例18: Connect

        public Connect(EndPoint remoteEndPoint)
        {
            if (remoteEndPoint == null)
                throw new ArgumentNullException("remoteEndPoint");

            _remoteEndPoint = remoteEndPoint;
        }
开发者ID:chrisecotrol,项目名称:griffin.networking,代码行数:7,代码来源:Connect.cs


示例19: ForConnectionPool

 // static methods
 internal static MongoWaitQueueFullException ForConnectionPool(EndPoint endPoint)
 {
     var message = string.Format(
         "The wait queue for acquiring a connection to server {0} is full.",
         EndPointHelper.ToString(endPoint));
     return new MongoWaitQueueFullException(message);
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:8,代码来源:MongoWaitQueueFullException.cs


示例20: beginWrite

        public void beginWrite(EndPoint endpoint, Buffer buf)
        {
            if(!(endpoint is IPEndPoint))
            {
                throw new Ice.FeatureNotSupportedException("SOCKS4 does not support domain names");
            }
            else if(endpoint.AddressFamily != AddressFamily.InterNetwork)
            {
                throw new Ice.FeatureNotSupportedException("SOCKS4 only supports IPv4 addresses");
            }

            //
            // SOCKS connect request
            //
            IPEndPoint addr = (IPEndPoint)endpoint;
            buf.resize(9, false);
            ByteBuffer.ByteOrder order = buf.b.order();
            buf.b.order(ByteBuffer.ByteOrder.BIG_ENDIAN); // Network byte order.
            buf.b.position(0);
            buf.b.put(0x04); // SOCKS version 4.
            buf.b.put(0x01); // Command, establish a TCP/IP stream connection
            buf.b.putShort((short)addr.Port); // Port
            buf.b.put(addr.Address.GetAddressBytes()); // IPv4 address
            buf.b.put(0x00); // User ID.
            buf.b.position(0);
            buf.b.limit(buf.size());
            buf.b.order(order);
        }
开发者ID:joshmoore,项目名称:ice,代码行数:28,代码来源:NetworkProxy.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Net.FtpWebRequest类代码示例发布时间:2022-05-26
下一篇:
C# Net.DownloadStringCompletedEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap