本文整理汇总了C#中UdpClient.BeginSend方法的典型用法代码示例。如果您正苦于以下问题:C# UdpClient.BeginSend方法的具体用法?C# UdpClient.BeginSend怎么用?C# UdpClient.BeginSend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpClient
的用法示例。
在下文中一共展示了UdpClient.BeginSend方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginSend_Success
public void BeginSend_Success()
{
UdpClient udpClient = new UdpClient();
byte[] sendBytes = new byte[1];
IPEndPoint remoteServer = new IPEndPoint(IPAddress.Loopback, TestPortBase + 2);
_waitHandle.Reset();
udpClient.BeginSend(sendBytes, sendBytes.Length, remoteServer, new AsyncCallback(AsyncCompleted), udpClient);
Assert.True(_waitHandle.WaitOne(5000), "Timed out while waiting for connection");
}
示例2: BeginSend_AsyncOperationCompletes_Success
public void BeginSend_AsyncOperationCompletes_Success()
{
UdpClient udpClient = new UdpClient();
byte[] sendBytes = new byte[1];
IPEndPoint remoteServer = new IPEndPoint(IPAddress.Loopback, UnusedPort);
_waitHandle.Reset();
udpClient.BeginSend(sendBytes, sendBytes.Length, remoteServer, new AsyncCallback(AsyncCompleted), udpClient);
Assert.True(_waitHandle.WaitOne(Configuration.PassingTestTimeout), "Timed out while waiting for connection");
}
示例3: BeginSend_BytesMoreThanArrayLength_Throws
public void BeginSend_BytesMoreThanArrayLength_Throws()
{
UdpClient udpClient = new UdpClient(AddressFamily.InterNetwork);
byte[] sendBytes = new byte[1];
IPEndPoint remoteServer = new IPEndPoint(IPAddress.Loopback, UnusedPort);
Assert.Throws<ArgumentOutOfRangeException>("bytes", () =>
{
udpClient.BeginSend(sendBytes, sendBytes.Length + 1, remoteServer, new AsyncCallback(AsyncCompleted), udpClient);
});
}
示例4: BeginSend_NegativeBytes_Throws
public void BeginSend_NegativeBytes_Throws()
{
UdpClient udpClient = new UdpClient();
byte[] sendBytes = new byte[1];
IPEndPoint remoteServer = new IPEndPoint(IPAddress.Loopback, UnusedPort);
Assert.Throws<ArgumentOutOfRangeException>("bytes", () =>
{
udpClient.BeginSend(sendBytes, -1, remoteServer, new AsyncCallback(AsyncCompleted), udpClient);
});
}
示例5: FindServer
private void FindServer(int _ListenPort, int _BroadcastPort)
{
System.Diagnostics.Debug.Assert(m_BroadcastClientLAN == null);
// open a broadcast on known port and
// send own broadcast listener port to the LAN
IPEndPoint ep2 = new IPEndPoint(IPAddress.Broadcast, _BroadcastPort);
UdpClient uc2 = new UdpClient();
// Important!
// this is disabled by default
// so we have to enable it
uc2.EnableBroadcast = true;
UdpClientState ucs2 = new UdpClientState(ep2, uc2);
byte[] sendBytes = System.BitConverter.GetBytes(_ListenPort);
uc2.BeginSend(sendBytes, sendBytes.Length, ep2, new System.AsyncCallback(FindServerCallback), ucs2);
m_BroadcastClientLAN = ucs2;
Debug.Log("Find server message sent on broadcast port " + _BroadcastPort);
}
示例6: FindServer
public void FindServer()
{
// open a broadcast on known port 15000 and
// send own broadcast listener port to the LAN
UdpClient uc2 = new UdpClient();
byte [] sendBytes = BitConverter.GetBytes(broadcastEndPoint.Port);
// Important!
// this is disabled by default
// so we have to enable it
uc2.EnableBroadcast = true;
IPEndPoint ep2 = new IPEndPoint(IPAddress.Broadcast, 15000);
uc2.BeginSend(sendBytes, sendBytes.Length, ep2, new AsyncCallback(FindServerCallback), uc2);
waitingResponse = true;
Debug.Log("Find server message sent on broadcast listener");
}
示例7: ListenForClientsCallback
public void ListenForClientsCallback(IAsyncResult ar)
{
// we received a broadcast from a client
Debug.Log("Client message received on server listening port");
UdpClient uc1 = (UdpClient)((UdpState)(ar.AsyncState)).u;
IPEndPoint ep1 = (IPEndPoint)((UdpState)(ar.AsyncState)).e;
byte[] receiveBytes = uc1.EndReceive(ar, ref ep1);
clientPort = BitConverter.ToInt32(receiveBytes,0);
Debug.Log("Client is listening for reply on broadcast port " + clientPort.ToString());
// send a response back to the client on the port
// they sent us
sentData = multiGameName;
byte [] sendBytes = Encoding.ASCII.GetBytes(sentData);
UdpClient uc2 = new UdpClient();
IPEndPoint ep2 = new IPEndPoint(ep1.Address, clientPort);
uc2.BeginSend(sendBytes, sendBytes.Length, ep2, new AsyncCallback(RespondClientCallback), uc2);
// Important!
// close and re-open the broadcast listening port
// so that another async operation can start
uc1.Close();
Debug.Log("server listening port closed");
ListenForClients(multiGameName);
waitingResponse = true;
}
示例8: RespondClient
private void RespondClient(IPAddress _ClientAddress, int _ClientPort, byte[] _DataToSend)
{
System.Diagnostics.Debug.Assert(m_AdvertisingClientLAN == null);
IPEndPoint ep2 = new IPEndPoint(_ClientAddress, _ClientPort);
UdpClient uc2 = new UdpClient(); //@FIXME: doesn't need to pass EndPoint in constructor?
UdpClientState ucs2 = new UdpClientState(ep2, uc2);
uc2.BeginSend(_DataToSend, _DataToSend.Length, ep2, new System.AsyncCallback(RespondClientCallback), ucs2);
m_AdvertisingClientLAN = ucs2;
}