我想做这个
for (int i = 0; i < 100; i++ )
{
Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
}
Run Code Online (Sandbox Code Playgroud)
但UdpClient.Receive我不得不使用,而不是使用UdpClient.BeginReceive.问题是,我该怎么做?没有很多样本使用BeginReceive,MSDN示例根本没有帮助.我应该使用BeginReceive,还是只在一个单独的线程下创建它?
我一直都是ObjectDisposedException例外.我只收到第一个发送的数据.下一个数据将抛出异常.
public class UdpReceiver
{
private UdpClient _client;
public System.Net.Sockets.UdpClient Client
{
get { return _client; }
set { _client = value; }
}
private IPEndPoint _endPoint;
public System.Net.IPEndPoint EndPoint
{
get { return _endPoint; }
set { _endPoint = value; }
}
private int _packetCount;
public int PacketCount
{
get …Run Code Online (Sandbox Code Playgroud) 我正在使用如下的UDPClient
dim c = New UDPClient(port)
client.CLient.ReceiveTimeout = 1
await client.ReceiveAsync()
Run Code Online (Sandbox Code Playgroud)
但是,即使我设置了超时,await也不会终止或抛出.这是正常的行为吗?