当前位置: 首页>>代码示例>>C#>>正文


C# UdpClient.BeginSend方法代码示例

本文整理汇总了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");
        }
开发者ID:hitomi333,项目名称:corefx,代码行数:10,代码来源:UdpClientTest.cs

示例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");
        }
开发者ID:nbilling,项目名称:corefx,代码行数:10,代码来源:UdpClientTest.cs

示例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);
            });
        }
开发者ID:nbilling,项目名称:corefx,代码行数:11,代码来源:UdpClientTest.cs

示例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);
            });
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:11,代码来源:UdpClientTest.cs

示例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);
    }
开发者ID:mhoulier,项目名称:unity3d_template,代码行数:23,代码来源:NetworkServerSearch.cs

示例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");
    }
开发者ID:bernarde-bgi,项目名称:bgirpsg,代码行数:21,代码来源:networkController.cs

示例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;
    }
开发者ID:bernarde-bgi,项目名称:bgirpsg,代码行数:33,代码来源:networkController.cs

示例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;
    }
开发者ID:mhoulier,项目名称:unity3d_template,代码行数:11,代码来源:NetworkServer.cs


注:本文中的UdpClient.BeginSend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。