本文整理匯總了C#中System.Net.Sockets.UdpClient.BeginSend方法的典型用法代碼示例。如果您正苦於以下問題:C# UdpClient.BeginSend方法的具體用法?C# UdpClient.BeginSend怎麽用?C# UdpClient.BeginSend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Net.Sockets.UdpClient
的用法示例。
在下文中一共展示了UdpClient.BeginSend方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SendCallback
public static bool messageSent = false;
public static void SendCallback(IAsyncResult ar)
{
UdpClient u = (UdpClient)ar.AsyncState;
Console.WriteLine($"number of bytes sent: {u.EndSend(ar)}");
messageSent = true;
}
示例2: SendMessage3
static void SendMessage3(string server, string message)
{
// create the udp socket
UdpClient u = new UdpClient();
byte[] sendBytes = Encoding.ASCII.GetBytes(message);
// send the message
// the destination is defined by the server name and port
u.BeginSend(sendBytes, sendBytes.Length, server, s_listenPort, new AsyncCallback(SendCallback), u);
// Do some work while we wait for the send to complete. For this example, we'll just sleep
while (!messageSent)
{
Thread.Sleep(100);
}
}
示例3: SendMessage1
static void SendMessage1(string server, string message)
{
// create the udp socket
UdpClient u = new UdpClient();
u.Connect(server, s_listenPort);
byte[] sendBytes = Encoding.ASCII.GetBytes(message);
// send the message
// the destination is defined by the call to .Connect()
u.BeginSend(sendBytes, sendBytes.Length, new AsyncCallback(SendCallback), u);
// Do some work while we wait for the send to complete. For this example, we'll just sleep
while (!messageSent)
{
Thread.Sleep(100);
}
}
示例4: SendMessage2
static void SendMessage2(string server, string message)
{
// create the udp socket
UdpClient u = new UdpClient();
byte[] sendBytes = Encoding.ASCII.GetBytes(message);
// resolve the server name
IPHostEntry heserver = Dns.GetHostEntry(server);
IPEndPoint e = new IPEndPoint(heserver.AddressList[0], s_listenPort);
// send the message
// the destination is defined by the IPEndPoint
u.BeginSend(sendBytes, sendBytes.Length, e, new AsyncCallback(SendCallback), u);
// Do some work while we wait for the send to complete. For this example, we'll just sleep
while (!messageSent)
{
Thread.Sleep(100);
}
}