本文整理汇总了C#中Socket.SendPacketsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.SendPacketsAsync方法的具体用法?C# Socket.SendPacketsAsync怎么用?C# Socket.SendPacketsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.SendPacketsAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Unix_NotSupported_ThrowsPlatformNotSupportedException
public void Unix_NotSupported_ThrowsPlatformNotSupportedException(SocketImplementationType type)
{
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
using (var sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
using (var args = new SocketAsyncEventArgs())
{
sock.Connect(new IPEndPoint(_serverAddress, port));
args.SendPacketsElements = new SendPacketsElement[1];
Assert.Throws<PlatformNotSupportedException>(() => sock.SendPacketsAsync(args));
}
}
示例2: Disposed_Throw
public void Disposed_Throw()
{
using (SocketTestServer.SocketTestServerFactory(Server))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(Server);
sock.Dispose();
Assert.Throws<ObjectDisposedException>(() =>
{
sock.SendPacketsAsync(new SocketAsyncEventArgs());
});
}
}
}
示例3: NullArgs_Throw
public void NullArgs_Throw(SocketImplementationType type)
{
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(new IPEndPoint(_serverAddress, port));
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
{
sock.SendPacketsAsync(null);
});
Assert.Equal("e", ex.ParamName);
}
}
}
示例4: Disposed_Throw
public void Disposed_Throw(SocketImplementationType type)
{
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(new IPEndPoint(_serverAddress, port));
sock.Dispose();
Assert.Throws<ObjectDisposedException>(() =>
{
sock.SendPacketsAsync(new SocketAsyncEventArgs());
});
}
}
}
示例5: SendPackets
private void SendPackets(SocketImplementationType type, SendPacketsElement[] elements, SocketError expectedResut, int bytesExpected)
{
Assert.True(Capability.IPv6Support());
EventWaitHandle completed = new ManualResetEvent(false);
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(new IPEndPoint(_serverAddress, port));
using (SocketAsyncEventArgs args = new SocketAsyncEventArgs())
{
args.Completed += OnCompleted;
args.UserToken = completed;
args.SendPacketsElements = elements;
if (sock.SendPacketsAsync(args))
{
Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out");
}
Assert.Equal(expectedResut, args.SocketError);
Assert.Equal(bytesExpected, args.BytesTransferred);
}
}
}
}
示例6: BufferZeroCountThenNormal_ZeroCountIgnored
public void BufferZeroCountThenNormal_ZeroCountIgnored(SocketImplementationType type)
{
Assert.True(Capability.IPv6Support());
EventWaitHandle completed = new ManualResetEvent(false);
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(new IPEndPoint(_serverAddress, port));
using (SocketAsyncEventArgs args = new SocketAsyncEventArgs())
{
args.Completed += OnCompleted;
args.UserToken = completed;
// First do an empty send, ignored
args.SendPacketsElements = new SendPacketsElement[]
{
new SendPacketsElement(new byte[5], 3, 0)
};
if (sock.SendPacketsAsync(args))
{
Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out");
}
Assert.Equal(SocketError.Success, args.SocketError);
Assert.Equal(0, args.BytesTransferred);
completed.Reset();
// Now do a real send
args.SendPacketsElements = new SendPacketsElement[]
{
new SendPacketsElement(new byte[5], 1, 4)
};
if (sock.SendPacketsAsync(args))
{
Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out");
}
Assert.Equal(SocketError.Success, args.SocketError);
Assert.Equal(4, args.BytesTransferred);
}
}
}
}
示例7: NotConnected_Throw
public void NotConnected_Throw()
{
Socket socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
// Needs to be connected before send
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
{
socket.SendPacketsAsync(new SocketAsyncEventArgs());
});
Assert.Equal("e.SendPacketsElements", ex.ParamName);
}
示例8: SendPackets
private void SendPackets(SocketImplementationType type, SendPacketsElement element, TransmitFileOptions flags, int bytesExpected)
{
Assert.True(Capability.IPv6Support());
EventWaitHandle completed = new ManualResetEvent(false);
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(new IPEndPoint(_serverAddress, port));
using (SocketAsyncEventArgs args = new SocketAsyncEventArgs())
{
args.Completed += OnCompleted;
args.UserToken = completed;
args.SendPacketsElements = new[] { element };
args.SendPacketsFlags = flags;
if (sock.SendPacketsAsync(args))
{
Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out");
}
Assert.Equal(SocketError.Success, args.SocketError);
Assert.Equal(bytesExpected, args.BytesTransferred);
}
switch (flags)
{
case TransmitFileOptions.Disconnect:
// Sending data again throws with socket shut down error.
Assert.Throws<SocketException>(() => { sock.Send(new byte[1] { 01 }); });
break;
case TransmitFileOptions.ReuseSocket & TransmitFileOptions.Disconnect:
// Able to send data again with reuse socket flag set.
Assert.Equal(1, sock.Send(new byte[1] { 01 }));
break;
}
}
}
}
示例9: NullArgs_Throw
public void NullArgs_Throw()
{
using (SocketTestServer.SocketTestServerFactory(Server))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(Server);
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
{
sock.SendPacketsAsync(null);
});
Assert.Equal("e", ex.ParamName);
}
}
}