• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SocketImplementationType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中SocketImplementationType的典型用法代码示例。如果您正苦于以下问题:C# SocketImplementationType类的具体用法?C# SocketImplementationType怎么用?C# SocketImplementationType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SocketImplementationType类属于命名空间,在下文中一共展示了SocketImplementationType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: RunClient

        public long RunClient(
            SocketImplementationType testType,
            string server,
            int port,
            int iterations,
            int bufferSize,
            int socketInstances)
        {
            _log.WriteLine(
                _format,
                "Implementation",
                "Type",
                "Buffer Size",
                "Iterations",
                "Init(ms)",
                "Connect(ms)",
                "SendRecv(ms)",
                "Close(ms)",
                "Total time");

            Task[] tasks = new Task[socketInstances];

            char[] charBuffer = new char[bufferSize];

            for (int i = 0; i < bufferSize; i++)
            {
                checked
                {
                    charBuffer[i] = (char)(i % 26 + 65);
                }
            }

            string message = new string(charBuffer);

            Stopwatch timeProgramStart = new Stopwatch();
            timeProgramStart.Start();

            Parallel.For(
                0,
                socketInstances,
                (i) =>
                {
                    var test = SocketTestClient.SocketTestClientFactory(
                        _log,
                        testType,
                        server,
                        port,
                        iterations,
                        message,
                        timeProgramStart);

                    tasks[i] = test.RunTest();
                });

            Task.WaitAll(tasks);

            timeProgramStart.Stop();

            return timeProgramStart.ElapsedMilliseconds;
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:60,代码来源:SocketPerformanceTests.cs


示例2: ClientServerTest

        public void ClientServerTest(
            int port, 
            SocketImplementationType serverType, 
            SocketImplementationType clientType, 
            int iterations, 
            int bufferSize, 
            int socket_instances, 
            long expectedMilliseconds)
        {
            long milliseconds;

#if arm
        iterations /= 100;
#endif

            using (SocketTestServer.SocketTestServerFactory(
                serverType,
                socket_instances * 5,
                bufferSize * 2,
                new IPEndPoint(IPAddress.IPv6Loopback, port)))
            {
                milliseconds = RunClient(
                    clientType,
                    "localhost",
                    port,
                    iterations,
                    bufferSize,
                    socket_instances);
            }

            Assert.True(
                milliseconds < expectedMilliseconds,
                "Test execution is expected to be shorter than " + expectedMilliseconds + " but was " + milliseconds);
        }
开发者ID:TAdityaAnirudh,项目名称:corefx,代码行数:34,代码来源:SocketPerformanceTests.cs


示例3: ClientServerTest

 public void ClientServerTest(
     SocketImplementationType serverType,
     SocketImplementationType clientType,
     int iterations,
     int bufferSize,
     int socketInstances,
     long expectedMilliseconds)
 {
     // NOTE: port '0' below indicates that the server should bind to an anonymous port.
     ClientServerTest(0, serverType, clientType, iterations, bufferSize, socketInstances, expectedMilliseconds);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:SocketPerformanceTests.cs


示例4: Socket_ConnectDnsEndPoint_Success

        public void Socket_ConnectDnsEndPoint_Success(SocketImplementationType type)
        {
            int port;
            SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port);

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Connect(new DnsEndPoint("localhost", port));

            sock.Dispose();
            server.Dispose();
        }
开发者ID:shmao,项目名称:corefx,代码行数:11,代码来源:DnsEndPointTest.cs


示例5: SocketTestServerFactory

 public static SocketTestServer SocketTestServerFactory(
     SocketImplementationType type,
     int numConnections,
     int receiveBufferSize,
     IPAddress address,
     out int port)
 {
     SocketTestServer server = SocketTestServerFactory(type, numConnections, receiveBufferSize, new IPEndPoint(address, 0));
     port = server.Port;
     return server;
 }
开发者ID:natemcmaster,项目名称:corefx,代码行数:11,代码来源:SocketTestServer.cs


示例6: Unix_NotSupported_ThrowsPlatformNotSupportedException

 public void Unix_NotSupported_ThrowsPlatformNotSupportedException(SocketImplementationType type)
 {
     int port;
     using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
     using (var sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
     using (var args = new SocketAsyncEventArgs())
     {
         sock.Connect(new IPEndPoint(_serverAddress, port));
         args.SendPacketsElements = new SendPacketsElement[1];
         Assert.Throws<PlatformNotSupportedException>(() => sock.SendPacketsAsync(args));
     }
 }
开发者ID:Corillian,项目名称:corefx,代码行数:12,代码来源:SendPacketsAsync.cs


示例7: Disposed_Throw

        public void Disposed_Throw(SocketImplementationType type)
        {
            int port;
            using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
            {
                using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
                {
                    sock.Connect(new IPEndPoint(_serverAddress, port));
                    sock.Dispose();

                    Assert.Throws<ObjectDisposedException>(() =>
                    {
                        sock.SendPacketsAsync(new SocketAsyncEventArgs());
                    });
                }
            }
        }
开发者ID:Corillian,项目名称:corefx,代码行数:17,代码来源:SendPacketsAsync.cs


示例8: ConnectEx_Success

        public void ConnectEx_Success(SocketImplementationType type)
        {
            Assert.True(Capability.IPv4Support() && Capability.IPv6Support());

            int port;
            SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port);

            int port6;
            SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port6);

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, port);
                args.Completed += OnConnectAsyncCompleted;

                ManualResetEvent complete = new ManualResetEvent(false);
                args.UserToken = complete;

                Assert.True(sock.ConnectAsync(args));
                Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "IPv4: Timed out while waiting for connection");
                Assert.True(args.SocketError == SocketError.Success);

                sock.Dispose();

                sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
                args.RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, port6);
                complete.Reset();

                Assert.True(sock.ConnectAsync(args));
                Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "IPv6: Timed out while waiting for connection");
                Assert.True(args.SocketError == SocketError.Success);
            }
            finally
            {
                sock.Dispose();

                server.Dispose();
                server6.Dispose();
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:43,代码来源:ConnectExTest.cs


示例9: ConnectAsync_IPv6_Success

        public void ConnectAsync_IPv6_Success(SocketImplementationType type)
        {
            Assert.True(Capability.IPv6Support());

            AutoResetEvent completed = new AutoResetEvent(false);

            int port;
            using (SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port))
            {
                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, port);
                args.Completed += OnConnectCompleted;
                args.UserToken = completed;

                using (Socket client = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
                {
                    Assert.True(client.ConnectAsync(args));
                    Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "IPv6: Timed out while waiting for connection");
                    Assert.Equal<SocketError>(SocketError.Success, args.SocketError);
                }
            }
        }
开发者ID:Corillian,项目名称:corefx,代码行数:22,代码来源:ConnectAsync.cs


示例10: SocketTestClientFactory

        public static SocketTestClient SocketTestClientFactory(
            ITestOutputHelper log,
            SocketImplementationType type,
            string server,
            int port,
            int iterations,
            string message,
            Stopwatch timeProgramStart)
        {
            switch (type)
            {
                case SocketImplementationType.APM:
                    var socketAPM = new SocketTestClientAPM(log, server, port, iterations, message, timeProgramStart);
                    log.WriteLine(socketAPM.GetHashCode() + " SocketTestClientAPM(..)");
                    return socketAPM;
                case SocketImplementationType.Async:
                    var socketAsync = new SocketTestClientAsync(log, server, port, iterations, message, timeProgramStart);
                    log.WriteLine(socketAsync.GetHashCode() + " SocketTestClientAsync(..)");
                    return socketAsync;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type));
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:24,代码来源:SocketTestClient.cs


示例11: NullArgs_Throw

        public void NullArgs_Throw(SocketImplementationType type)
        {
            int port;
            using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
            {
                using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
                {
                    sock.Connect(new IPEndPoint(_serverAddress, port));

                    ArgumentNullException ex = Assert.Throws<ArgumentNullException>(() =>
                    {
                        sock.SendPacketsAsync(null);
                    });
                    Assert.Equal("e", ex.ParamName);
                }
            }
        }
开发者ID:Corillian,项目名称:corefx,代码行数:17,代码来源:SendPacketsAsync.cs


示例12: EmptyBuffer_Ignored

 public void EmptyBuffer_Ignored(SocketImplementationType type)
 {
     SendPackets(type, new SendPacketsElement(new byte[0]), 0);
 }
开发者ID:Corillian,项目名称:corefx,代码行数:4,代码来源:SendPacketsAsync.cs


示例13: BufferZeroCount_Ignored

 public void BufferZeroCount_Ignored(SocketImplementationType type)
 {
     SendPackets(type, new SendPacketsElement(new byte[10], 4, 0), 0);
 }
开发者ID:Corillian,项目名称:corefx,代码行数:4,代码来源:SendPacketsAsync.cs


示例14: SendPackets

        private void SendPackets(SocketImplementationType type, SendPacketsElement[] elements, SocketError expectedResut, int bytesExpected)
        {
            Assert.True(Capability.IPv6Support());

            EventWaitHandle completed = new ManualResetEvent(false);

            int port;
            using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
            {
                using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
                {
                    sock.Connect(new IPEndPoint(_serverAddress, port));
                    using (SocketAsyncEventArgs args = new SocketAsyncEventArgs())
                    {
                        args.Completed += OnCompleted;
                        args.UserToken = completed;
                        args.SendPacketsElements = elements;

                        if (sock.SendPacketsAsync(args))
                        {
                            Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out");
                        }
                        Assert.Equal(expectedResut, args.SocketError);
                        Assert.Equal(bytesExpected, args.BytesTransferred);
                    }
                }
            }
        }
开发者ID:Corillian,项目名称:corefx,代码行数:28,代码来源:SendPacketsAsync.cs


示例15: SendPacketsElement_FileLargeCount_Throws

 public void SendPacketsElement_FileLargeCount_Throws(SocketImplementationType type)
 {
     // Length is validated on Send
     SendPackets(type, new SendPacketsElement(TestFileName, 5, 10000), SocketError.InvalidArgument, 0);
 }
开发者ID:Corillian,项目名称:corefx,代码行数:5,代码来源:SendPacketsAsync.cs


示例16: SendPacketsElement_FileMultiPart_Success

 public void SendPacketsElement_FileMultiPart_Success(SocketImplementationType type)
 {
     SendPacketsElement[] elements = new SendPacketsElement[]
     {
         new SendPacketsElement(TestFileName, 10, 20),
         new SendPacketsElement(TestFileName, 30, 10),
         new SendPacketsElement(TestFileName, 0, 10),
     };
     SendPackets(type, elements, SocketError.Success, 40);
 }
开发者ID:Corillian,项目名称:corefx,代码行数:10,代码来源:SendPacketsAsync.cs


示例17: SendPacketsElement_FilePart_Success

 public void SendPacketsElement_FilePart_Success(SocketImplementationType type)
 {
     SendPackets(type, new SendPacketsElement(TestFileName, 10, 20), 20);
 }
开发者ID:Corillian,项目名称:corefx,代码行数:4,代码来源:SendPacketsAsync.cs


示例18: Socket_StaticConnectAsync_Success

        public void Socket_StaticConnectAsync_Success(SocketImplementationType type)
        {
            Assert.True(Capability.IPv4Support() && Capability.IPv6Support());

            int port4, port6;
            SocketTestServer server4 = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port4);
            SocketTestServer server6 = SocketTestServer.SocketTestServerFactory(type, IPAddress.IPv6Loopback, out port6);

            SocketAsyncEventArgs args = new SocketAsyncEventArgs();
            args.RemoteEndPoint = new DnsEndPoint("localhost", port4);
            args.Completed += OnConnectAsyncCompleted;

            ManualResetEvent complete = new ManualResetEvent(false);
            args.UserToken = complete;

            Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args));

            Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");

            Assert.Equal(SocketError.Success, args.SocketError);
            Assert.Null(args.ConnectByNameError);
            Assert.NotNull(args.ConnectSocket);
            Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetwork);
            Assert.True(args.ConnectSocket.Connected);

            args.ConnectSocket.Dispose();

            args.RemoteEndPoint = new DnsEndPoint("localhost", port6);
            complete.Reset();

            Assert.True(Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, args));

            Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");

            Assert.Equal(SocketError.Success, args.SocketError);
            Assert.Null(args.ConnectByNameError);
            Assert.NotNull(args.ConnectSocket);
            Assert.True(args.ConnectSocket.AddressFamily == AddressFamily.InterNetworkV6);
            Assert.True(args.ConnectSocket.Connected);

            args.ConnectSocket.Dispose();

            server4.Dispose();
            server6.Dispose();
        }
开发者ID:shmao,项目名称:corefx,代码行数:45,代码来源:DnsEndPointTest.cs


示例19: SendPacketsElement_BadCharactersFileName_Throws

 public void SendPacketsElement_BadCharactersFileName_Throws(SocketImplementationType type)
 {
     Assert.Throws<ArgumentException>(() =>
     {
         // Existence is validated on send
         SendPackets(type, new SendPacketsElement("[email protected]?/sqersf"), 0);
     });
 }
开发者ID:Corillian,项目名称:corefx,代码行数:8,代码来源:SendPacketsAsync.cs


示例20: SendPacketsElement_BlankFileName_Throws

 public void SendPacketsElement_BlankFileName_Throws(SocketImplementationType type)
 {
     Assert.Throws<ArgumentException>(() =>
     {
         // Existence is validated on send
         SendPackets(type, new SendPacketsElement(" \t  "), 0);
     });
 }
开发者ID:Corillian,项目名称:corefx,代码行数:8,代码来源:SendPacketsAsync.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SocketOperation类代码示例发布时间:2022-05-24
下一篇:
C# SocketFlags类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap