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


C# Socket.BeginSendTo方法代码示例

本文整理汇总了C#中Socket.BeginSendTo方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.BeginSendTo方法的具体用法?C# Socket.BeginSendTo怎么用?C# Socket.BeginSendTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Socket的用法示例。


在下文中一共展示了Socket.BeginSendTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DualModeBeginSendTo_EndPointToHost_Helper

        private void DualModeBeginSendTo_EndPointToHost_Helper(IPAddress connectTo, IPAddress listenOn, bool dualModeServer, bool expectedToTimeout = false)
        {
            int port;
            Socket client = new Socket(SocketType.Dgram, ProtocolType.Udp);
            using (SocketUdpServer server = new SocketUdpServer(_log, listenOn, dualModeServer, out port))
            {
                // Send a few packets, in case they aren't delivered reliably.
                for (int i = 0; i < Configuration.UDPRedundancy; i++)
                {
                    IAsyncResult async = client.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new IPEndPoint(connectTo, port), null, null);

                    int sent = client.EndSendTo(async);
                    Assert.Equal(1, sent);
                }

                bool success = server.WaitHandle.WaitOne(expectedToTimeout ? Configuration.FailingTestTimeout : Configuration.PassingTestTimeout); // Make sure the bytes were received
                if (!success)
                {
                    throw new TimeoutException();
                }
            }
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:22,代码来源:DualModeSocketTest.cs

示例2: Socket_BeginSendToDnsEndPoint_Throws

        [Fact] // Base case
        // "The parameter remoteEP must not be of type DnsEndPoint."
        public void Socket_BeginSendToDnsEndPoint_Throws()
        {
            Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp);

            Assert.Throws<ArgumentException>(() =>
            {
                socket.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new DnsEndPoint("localhost", UnusedPort), null, null);
            });
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:11,代码来源:DualModeSocketTest.cs

示例3: Socket_BeginSendToV4IPEndPointToV4Host_Throws

        [Fact] // Base case
        // "The system detected an invalid pointer address in attempting to use a pointer argument in a call"
        public void Socket_BeginSendToV4IPEndPointToV4Host_Throws()
        {
            Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp);
            socket.DualMode = false;

            Assert.Throws<SocketException>(() =>
            {
                socket.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new IPEndPoint(IPAddress.Loopback, UnusedPort), null, null);
            });
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:12,代码来源:DualModeSocketTest.cs

示例4: DualModeBeginSendTo_EndPointToHost_Helper

        private void DualModeBeginSendTo_EndPointToHost_Helper(IPAddress connectTo, IPAddress listenOn, bool dualModeServer)
        {
            int port;
            Socket client = new Socket(SocketType.Dgram, ProtocolType.Udp);
            using (SocketUdpServer server = new SocketUdpServer(listenOn, dualModeServer, out port))
            {
                IAsyncResult async = client.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new IPEndPoint(connectTo, port), null, null);

                int sent = client.EndSendTo(async);
                Assert.Equal(1, sent);

                bool success = server.WaitHandle.WaitOne(100); // Make sure the bytes were received
                if (!success)
                {
                    throw new TimeoutException();
                }
            }
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:18,代码来源:DualModeSocketTest.cs

示例5: Socket_BeginSendToDnsEndPoint_ArgumentException

 public void Socket_BeginSendToDnsEndPoint_ArgumentException()
 {
     using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
     {
         Assert.Throws<ArgumentException>(() =>
         {
             sock.BeginSendTo(new byte[10], 0, 0, SocketFlags.None, new DnsEndPoint("localhost", UnusedPort), null, null);
         });
     }
 }
开发者ID:shmao,项目名称:corefx,代码行数:10,代码来源:DnsEndPointTest.cs

示例6: Send

 public void Send(string ip, int port, byte[] temp_sendbuffer)
 {
     socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     socket.BeginSendTo(temp_sendbuffer, 0, temp_sendbuffer.Length, SocketFlags.None, (EndPoint)(new IPEndPoint(IPAddress.Parse(ip), port)), new AsyncCallback(SendTo_Callback), socket);
 }
开发者ID:hhrhzy,项目名称:mywork,代码行数:5,代码来源:Network.cs


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