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


C# Socket.SetNetworkRequirement方法代码示例

本文整理汇总了C#中Socket.SetNetworkRequirement方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.SetNetworkRequirement方法的具体用法?C# Socket.SetNetworkRequirement怎么用?C# Socket.SetNetworkRequirement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Socket的用法示例。


在下文中一共展示了Socket.SetNetworkRequirement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connect

        public void Connect(string host, int port)
        {
            if (!IsConnected)
            {
                try
                {
                    SocketAsyncEventArgs e = new SocketAsyncEventArgs();
                    e.RemoteEndPoint = new DnsEndPoint(host, port);
                    e.Completed += OnRequestComplete;

                    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    socket.SetNetworkRequirement(NetworkSelectionCharacteristics.NonCellular);

                    if (!socket.ConnectAsync(e))
                        OnRequestComplete(null, e);
                }
                catch (Exception ex)
                {
                    //Close();
                    SafeInvokeEvent(Log, "Connect: " + ex.Message);
                }
            }
        }
开发者ID:KonstantinKolesnik,项目名称:EcosHub,代码行数:23,代码来源:TcpClient.cs

示例2: Initialize

        /// <summary>
        /// Initializes the wrapper with a set of local and remote endpoint data.
        /// </summary>
        /// <param name="localAddress">The local address to use for receive operations.</param>
        /// <param name="localPort">The local port to use for receive operations.</param>
        /// <param name="remoteAddress">The remote address to use for send operations.</param>
        /// <param name="remotePort">The remote port to use for send operations.</param>
        public void Initialize(string localAddress, int localPort, string remoteAddress, int remotePort)
        {
            IPEndPoint localEndPoint = null;
            if (!string.IsNullOrEmpty(localAddress))
            {
                localEndPoint = EndPointHelper.ParseEndPoint(localAddress, localPort);
            }
            var remoteEndPoint = EndPointHelper.ParseEndPoint(remoteAddress, remotePort);

            _logger.Trace("Initializing with local endpoint {0} and remote endpoint {1}",
                localEndPoint != null ? localEndPoint.ToString() : "{none}",
                remoteEndPoint);

            // set the remote endpoint
            _socketOperation.RemoteEndPoint = remoteEndPoint;

            // create socket
            _currentSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            #if WINDOWS_PHONE
            // make sure we only use the socket when we have a non-cellular (Wi-Fi or similar) connection
            _currentSocket.SetNetworkRequirement(NetworkSelectionCharacteristics.NonCellular);
            #endif

            // hook for the server side of code
            OnInitializedPartial(localEndPoint, remoteEndPoint);
        }
开发者ID:porter1130,项目名称:WP8-DEMO,代码行数:34,代码来源:UdpSocketWrapper.cs

示例3: Init

        /// <summary>
        /// Initialize DSMI for sending and receiving midi messages.
        /// </summary>
        public static void Init()
        {
            if (_init)
                return;

            _inSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            _inSocket.SetNetworkRequirement(NetworkSelectionCharacteristics.NonCellular);

            _inEndpoint = new IPEndPoint(IPAddress.Any, WP_PORT);
            _outEndpoint = new IPEndPoint(IPAddress.Broadcast, PC_PORT);

            _inSocket.Bind(_inEndpoint);

            _init = true;

            _clientDone.Reset();
            SendKeepAlive();
            _clientDone.WaitOne(100);

            Receive();
        }
开发者ID:alekhin0w,项目名称:dsmi,代码行数:25,代码来源:Midi.cs


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