本文整理汇总了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);
}
}
}
示例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);
}
示例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();
}