本文整理汇总了C#中Socket.BeginDisconnect方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.BeginDisconnect方法的具体用法?C# Socket.BeginDisconnect怎么用?C# Socket.BeginDisconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.BeginDisconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginDisconnect_NonWindows_NotSupported
public void BeginDisconnect_NonWindows_NotSupported()
{
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
Assert.Throws<PlatformNotSupportedException>(() => client.BeginDisconnect(true, null, null));
}
}
示例2: BeginDisconnect_Success
public void BeginDisconnect_Success()
{
AutoResetEvent completed = new AutoResetEvent(false);
IPEndPoint loopback = new IPEndPoint(IPAddress.Loopback, 0);
using (var server1 = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, loopback))
using (var server2 = SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, loopback))
{
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.Completed += OnCompleted;
args.UserToken = completed;
args.RemoteEndPoint = server1.EndPoint;
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
Assert.True(client.ConnectAsync(args));
completed.WaitOne();
Assert.Equal(SocketError.Success, args.SocketError);
client.EndDisconnect(client.BeginDisconnect(true, null, null));
args.RemoteEndPoint = server2.EndPoint;
Assert.True(client.ConnectAsync(args));
completed.WaitOne();
Assert.Equal(SocketError.Success, args.SocketError);
}
}
}