//BeginReceive
UdpClient client;
bool messageReceived = false;
public void Main()
{
client = new UdpClient(8080);
client.BeginReceive(ReceiveCallback, "flag");
//直接跳过
Console.WriteLine("完成");
if (!messageReceived)
Thread.Sleep(100);
}
private void ReceiveCallback(IAsyncResult ar)
{
if (ar.IsCompleted)
{
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
byte[] data = client.EndReceive(ar, ref ep);
Console.WriteLine("收到数据");
//收到数据
client.Close();
}
}
//Receive
public void Main()
{
using (UdpClient client = new UdpClient(8080))
{
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
byte[] data = client.Receive(ref ep);
Console.WriteLine("收到数据");
//等待直到收到数据
}
Console.WriteLine("完成");
}
Webservice和HTTP Restful都是常用的远程调用方式,但它们有一些区别:1. 协议:Webservice使用的是SOAP协议,而HTTP Restful使用的是HTTP协议。2. 消息格式:Webservice使用电商平台M...
点击进入详情页
本回答由
上海派拉软件股份有限公司
提供