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


C# SocketImplementationType类代码示例

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


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


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