本文整理汇总了C#中Socket.BeginSendTo方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.BeginSendTo方法的具体用法?C# Socket.BeginSendTo怎么用?C# Socket.BeginSendTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Socket
的用法示例。
在下文中一共展示了Socket.BeginSendTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DualModeBeginSendTo_EndPointToHost_Helper
private void DualModeBeginSendTo_EndPointToHost_Helper(IPAddress connectTo, IPAddress listenOn, bool dualModeServer, bool expectedToTimeout = false)
{
int port;
Socket client = new Socket(SocketType.Dgram, ProtocolType.Udp);
using (SocketUdpServer server = new SocketUdpServer(_log, listenOn, dualModeServer, out port))
{
// Send a few packets, in case they aren't delivered reliably.
for (int i = 0; i < Configuration.UDPRedundancy; i++)
{
IAsyncResult async = client.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new IPEndPoint(connectTo, port), null, null);
int sent = client.EndSendTo(async);
Assert.Equal(1, sent);
}
bool success = server.WaitHandle.WaitOne(expectedToTimeout ? Configuration.FailingTestTimeout : Configuration.PassingTestTimeout); // Make sure the bytes were received
if (!success)
{
throw new TimeoutException();
}
}
}
示例2: Socket_BeginSendToDnsEndPoint_Throws
[Fact] // Base case
// "The parameter remoteEP must not be of type DnsEndPoint."
public void Socket_BeginSendToDnsEndPoint_Throws()
{
Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp);
Assert.Throws<ArgumentException>(() =>
{
socket.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new DnsEndPoint("localhost", UnusedPort), null, null);
});
}
示例3: Socket_BeginSendToV4IPEndPointToV4Host_Throws
[Fact] // Base case
// "The system detected an invalid pointer address in attempting to use a pointer argument in a call"
public void Socket_BeginSendToV4IPEndPointToV4Host_Throws()
{
Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp);
socket.DualMode = false;
Assert.Throws<SocketException>(() =>
{
socket.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new IPEndPoint(IPAddress.Loopback, UnusedPort), null, null);
});
}
示例4: DualModeBeginSendTo_EndPointToHost_Helper
private void DualModeBeginSendTo_EndPointToHost_Helper(IPAddress connectTo, IPAddress listenOn, bool dualModeServer)
{
int port;
Socket client = new Socket(SocketType.Dgram, ProtocolType.Udp);
using (SocketUdpServer server = new SocketUdpServer(listenOn, dualModeServer, out port))
{
IAsyncResult async = client.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new IPEndPoint(connectTo, port), null, null);
int sent = client.EndSendTo(async);
Assert.Equal(1, sent);
bool success = server.WaitHandle.WaitOne(100); // Make sure the bytes were received
if (!success)
{
throw new TimeoutException();
}
}
}
示例5: Socket_BeginSendToDnsEndPoint_ArgumentException
public void Socket_BeginSendToDnsEndPoint_ArgumentException()
{
using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
Assert.Throws<ArgumentException>(() =>
{
sock.BeginSendTo(new byte[10], 0, 0, SocketFlags.None, new DnsEndPoint("localhost", UnusedPort), null, null);
});
}
}
示例6: Send
public void Send(string ip, int port, byte[] temp_sendbuffer)
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.BeginSendTo(temp_sendbuffer, 0, temp_sendbuffer.Length, SocketFlags.None, (EndPoint)(new IPEndPoint(IPAddress.Parse(ip), port)), new AsyncCallback(SendTo_Callback), socket);
}