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


C# SocketPair.Startup方法代码示例

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


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

示例1: SocketsEnums8_SocketFlags_Peek

        public MFTestResults SocketsEnums8_SocketFlags_Peek()
        {
            /// <summary>
            /// 1. Sends TCP data using the Peek flag 
            /// 2. Verifies that the correct exception is thrown
            /// Further testing would require harness alteration
            /// </summary>
            ///
            bool isAnyCatch = false;
            try
            {
                try
                {
                    SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
                    testSockets.Startup(0, 0);
                    testSockets.socketServer.Listen(1);
                    testSockets.socketClient.Connect(testSockets.epServer);

                    int cBytes = testSockets.socketClient.Send(testSockets.bufSend);

                    using (Socket sock = testSockets.socketServer.Accept())
                    {
                        cBytes = sock.Receive(testSockets.bufReceive, SocketFlags.Peek);
                        Log.Comment("Checking Peek data");
                        testSockets.AssertDataReceived(cBytes);
                        int cBytesAgain = sock.Receive(testSockets.bufReceive);

                        if(cBytesAgain < cBytes)
                            throw new Exception( 
                                "Peek returns more bytes than the successive read" );
                    }
                    testSockets.AssertDataReceived(cBytes);
                    testSockets.TearDown();
                    testSockets = null;
                }
                catch (SocketException)
                {
                    isAnyCatch = true;
                }
            }
            catch (System.Exception e)
            {
                isAnyCatch = true;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            if (!isAnyCatch)
            {
                Log.Comment("No exception caught");
            }
            return (isAnyCatch ? MFTestResults.Fail : MFTestResults.Pass);
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:51,代码来源:SocketsEnumsTests.cs

示例2: SocketTest1_TCP_NoDelay

        public MFTestResults SocketTest1_TCP_NoDelay()
        {
            ///<summary>
            ///1. Starts a server socket listening for TCP
            ///2. Starts a client socket connected to the server
            ///3. Verifies that data can be correctly sent and recieved
            ///4. Verifies NoDelay is functional
            ///</summary>

            ///skip this test for the emulator since setting socket options is not supported.
            if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
                return MFTestResults.Skip;

            MFTestResults testResult = MFTestResults.Pass;

            bool noDelay = false;
            int bytesReceivedNoDelay = 0;
            int bytesReceivedDelay = 0;

            do
            {
                SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

                try
                {

                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, noDelay);

                    Log.Comment("Testing with port 0");
                    testSockets.Startup(0, 0);

                    testSockets.socketServer.Listen(1);

                    testSockets.socketClient.Connect(testSockets.epServer);

                    Log.Comment("send lots of small packets.");
                    int bytesSent = 0;

                    for (int i = 0; i < 140; ++i)
                    {
                        bytesSent += testSockets.socketClient.Send(testSockets.bufSend);
                    }

                    using (Socket sock = testSockets.socketServer.Accept())
                    {
                        byte[] recBytes = new byte[486*testSockets.bufSend.Length];
                        int bytesReceived = sock.Available;
                        bytesReceived = sock.Receive(recBytes);

                        if (noDelay)
                            bytesReceivedNoDelay = bytesReceived;
                        else
                            bytesReceivedDelay = bytesReceived;

                        Log.Comment("BytesSent: " + bytesSent + " BytesReceived: " + bytesReceived);
                    }
                }
                catch (SocketException e)
                {
                    Log.Comment("Caught exception: " + e.Message);
                    Log.Comment("ErrorCode: " + e.ErrorCode.ToString());
                    testResult = MFTestResults.Fail;
                }
                catch (Exception e)
                {
                    Log.Comment("Caught exception: " + e.Message);
                    testResult = MFTestResults.Fail;
                }
                finally
                {
                    testSockets.TearDown();
                }
                noDelay = !noDelay;
            }
            while (noDelay);

            if (bytesReceivedNoDelay < bytesReceivedDelay)
            {
                testResult = MFTestResults.Fail;
                Log.Comment("We've received more bytes with nodelay enabled.");
            }
            return testResult;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:83,代码来源:SocketTests.cs

示例3: SocketTest13_DPWSOptions


//.........这里部分代码省略.........
                    byte[] local = localAddress.GetAddressBytes();

                    byte[] multicastOpt = new byte[] {     224,      100,        1,        1,
                                                          local[0], local[1], local[2], local[3]};

                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.IP,
                        SocketOptionName.DropMembership, multicastOpt);
                }
                catch (SocketException se)
                {
                    if (se.ErrorCode != (int)SocketError.ProtocolOption)
                    {
                        Log.Comment("Caught exception: " + se.Message);
                        if (se.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                            Log.Comment("ErrorCode: " + se.ErrorCode);
                        testResult = false;
                    }
                }
                catch (Exception e)
                {
                    Log.Comment("Caught exception: " + e.Message);
                    if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                        Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                    testResult = false;
                }
                try
                {
                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.Socket,
                        SocketOptionName.ReuseAddress, true);
                }
                catch (SocketException se)
                {
                    if (se.ErrorCode != (int)SocketError.ProtocolOption)
                    {
                        Log.Comment("Caught exception: " + se.Message);
                        if (se.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                            Log.Comment("ErrorCode: " + se.ErrorCode);
                        testResult = false;
                    }
                }
                catch (Exception e)
                {
                    Log.Comment("Caught exception: " + e.Message);
                    if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                        Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                    testResult = false;
                }
                try
                {
                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.Socket,
                        SocketOptionName.ReceiveBuffer, 0x1024);
                }
                catch (SocketException se)
                {
                    if (se.ErrorCode != (int)SocketError.ProtocolOption)
                    {
                        Log.Comment("Caught exception: " + se.Message);
                        if (se.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                            Log.Comment("ErrorCode: " + se.ErrorCode);
                        testResult = false;
                    }
                }
                catch (Exception e)
                {
                    Log.Comment("Caught exception: " + e.Message);
                    if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                        Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                    testResult = false;
                }

                Log.Comment("Testing with port 0");
                testSockets.Startup(0, 0);

                int cBytes = testSockets.socketClient.SendTo(testSockets.bufSend,
                    testSockets.epServer);

                if (cBytes != testSockets.bufSend.Length)
                    throw new Exception("Send failed, wrong length");


                EndPoint epFrom = new IPEndPoint(IPAddress.Any, 0);
                cBytes = testSockets.socketServer.ReceiveFrom(
                    testSockets.bufReceive, ref epFrom);

                if (testSockets.epClient.Address.ToString() !=
                    ((IPEndPoint)epFrom).Address.ToString())
                    throw new Exception("Bad address");

                testSockets.TearDown();
                testSockets = null;
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                    Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,代码来源:SocketTests.cs

示例4: SocketTest11_SetSocketOptionBasic

        public MFTestResults SocketTest11_SetSocketOptionBasic()
        {
            /// <summary>
            /// 1. Call SetSocketOption with each of its signatures
            /// </summary>
            ///
            bool isAnyCatch = false;
            try
            {
                SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

                // check the bool
                testSockets.socketClient.SetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.Linger, true);
                bool linger = (0 != (int)testSockets.socketClient.GetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.Linger));

                if (!linger)
                    throw new Exception("Linger was not enabled");

                int lingerTime = 20;

                testSockets.socketClient.SetSocketOption(SocketOptionLevel.Socket,
                    SocketOptionName.Linger, lingerTime);
                int lingerResult = (int)testSockets.socketClient.GetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.Linger);

                if (lingerResult != lingerTime)
                    throw new Exception("Linger time was not set correctly");

                // check the bool again for false
                testSockets.socketClient.SetSocketOption(SocketOptionLevel.Socket,
                    SocketOptionName.Linger, false);
                bool notLinger = (0 == (int)testSockets.socketClient.GetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.Linger));

                if (!notLinger)
                    throw new Exception("Linger was not disabled");

                // proceed to bind
                Log.Comment("Testing with port 0");
                testSockets.Startup(0, 0);

                testSockets.socketServer.Listen(1);
                testSockets.socketClient.Connect(testSockets.epServer);
                int cBytes = testSockets.socketClient.Send(testSockets.bufSend);

                using (Socket sock = testSockets.socketServer.Accept())
                {
                    cBytes = sock.Receive(testSockets.bufReceive);
                    testSockets.AssertDataReceived(cBytes);
                }
                testSockets.TearDown();
                testSockets = null;
            }
            catch (Exception e)
            {
                isAnyCatch = true;
                Log.Comment("Exception caught: " + e.Message);
                if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                    Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
            }
            return (!isAnyCatch ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:64,代码来源:SocketTests.cs

示例5: SocketTest10_TCPPoll

        public MFTestResults SocketTest10_TCPPoll()
        {
            /// <summary>
            /// 1. Starts a server socket listening for TCP
            /// 2. Starts a client socket connected to the server
            /// 3. Transfers some data
            /// 4. Verifies that Poll returns correct results after each individual
            /// function is called.
            /// </summary>
            ///
            bool testResult = true;

            try
            {
                SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
                Log.Comment("Testing with port 0");
                testSockets.Startup(0, 0);

                testSockets.socketServer.Listen(1);
                Log.Comment("Listen called");
                
                testSockets.socketClient.Connect(testSockets.epServer);
                Log.Comment("Connect called");

                int cBytes = testSockets.socketClient.Send(testSockets.bufSend);
                Log.Comment("Send called");
                testResult = (testSockets.socketClient.Poll(1000, SelectMode.SelectWrite) == true);
                testResult = (testSockets.socketServer.Poll(1000, SelectMode.SelectRead) == true);

                using (Socket sock = testSockets.socketServer.Accept())
                {
                    Log.Comment("Accept called");
                    testResult = (testSockets.socketClient.Poll(1000, SelectMode.SelectWrite) == true);

                    cBytes = sock.Available;
                    Log.Comment("Available bytes assigned");
                    testResult = (testSockets.socketClient.Poll(1000, SelectMode.SelectWrite) == true);

                    cBytes = sock.Receive(testSockets.bufReceive);
                    Log.Comment("Recieve called");
                    testResult = (testSockets.socketClient.Poll(1000, SelectMode.SelectWrite) == true);
                }

                testSockets.AssertDataReceived(cBytes);
                testSockets.TearDown();
                testSockets = null;
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                    Log.Comment("ErrorCode: " +
                        ((SocketException)e).ErrorCode); testResult = false;
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:57,代码来源:SocketTests.cs

示例6: SocketTest8_TCPRecieveFrom

        public MFTestResults SocketTest8_TCPRecieveFrom()
        {
            /// <summary>
            /// 1. Starts a server socket listening for TCP
            /// 2. Starts a client socket connected to the server
            /// 3. Verifies that data can be correctly sent and Recieved using 
            ///  each prototype of RecieveFrom method
            /// 4. Verifies that exceptions are correctly thrown for RecieveFrom calls that have
            ///  bad Offset or Size parameters
            /// </summary>
            ///
            MFTestResults testResult = MFTestResults.Pass;
            SocketPair testSockets = null;

            try
            {
                testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
                Log.Comment("Testing with port 0");
                testSockets.Startup(0, 0);

                EndPoint remoteEndPoint = testSockets.epClient.Create(testSockets.epClient.Serialize());
                testSockets.socketServer.Listen(1);
                testSockets.socketClient.Connect(testSockets.epServer);
                
                int cBytes = testSockets.socketClient.Send(testSockets.bufSend);
                using (Socket sock = testSockets.socketServer.Accept())
                {
                    cBytes = sock.ReceiveFrom(testSockets.bufReceive, 0, testSockets.bufSend.Length, SocketFlags.None, ref remoteEndPoint);
                }

                testSockets.AssertDataReceived(cBytes);
                testSockets.TearDown();
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception in RecieveFrom with Byte Array,"
                    + " Int, SocketFlags: " + e.Message);
                testResult = MFTestResults.Fail;
            }
            finally
            {
                if (testSockets != null)
                {
                    testSockets.TearDown();
                    testSockets = null;
                }
            }
            return testResult;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:49,代码来源:SocketTests.cs

示例7: SocketExceptionTest11_AccessDenied

        public MFTestResults SocketExceptionTest11_AccessDenied()
        {
            /// <summary>
            /// 1. Causes a AccessDenied error
            /// </summary>
            ///
            bool isCorrectCatch = false;
            bool isAnyCatch = false;
            SocketPair testSockets = new SocketPair(ProtocolType.Udp, SocketType.Dgram);
            try
            {
                try
                {
                    int clientPort = SocketTools.nextPort;
                    int serverPort = SocketTools.nextPort;
                    int tempPort = serverPort;
                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, false);
                    testSockets.Startup(clientPort, serverPort);
                    IPEndPoint epBroadcast = new IPEndPoint(SocketTools.DottedDecimalToIp((byte)255, (byte)255, (byte)255, (byte)255), tempPort);
                    EndPoint serverEndPoint = epBroadcast.Create(epBroadcast.Serialize());
                    testSockets.socketClient.SendTo(testSockets.bufSend, serverEndPoint);
                }
                catch (SocketException)
                {
                    isCorrectCatch = true;
                    isAnyCatch = true;
                }
            }
            catch (System.Exception e)
            {
                isAnyCatch = true;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            finally
            {
                testSockets.TearDown();
            }
            if (!isAnyCatch)
            {
                Log.Comment("No exception caught");
            }

            return (isCorrectCatch ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:44,代码来源:SocketExceptionTests.cs

示例8: SocketTest5_BasicRAW

        public MFTestResults SocketTest5_BasicRAW()
        {
            /// <summary>
            /// 1. Starts a server socket listening for Raw
            /// 2. Starts a client socket connected to the server
            /// 3. Verifies that data can be correctly sent and recieved
            /// </summary>
            ///
            bool testResult = true;
            SocketPair testSockets = null;
            try
            {
                testSockets = new SocketPair(ProtocolType.Raw, SocketType.Raw);
                testSockets.Startup(0, 0);
                testSockets.socketServer.Listen(1);
                testSockets.socketClient.Connect(testSockets.epServer);
                int cBytes = testSockets.socketClient.Send(testSockets.bufSend);

                if (cBytes != testSockets.bufSend.Length)
                    throw new Exception("Send failed, wrong length");

                using (Socket sock = testSockets.socketServer.Accept())
                {
                    if (sock.LocalEndPoint == null)
                        throw new Exception("LocalEndPoint is null");
                    //Fix?
                    if (testSockets.socketServer.LocalEndPoint.ToString() !=
                        sock.LocalEndPoint.ToString())
                        throw new Exception("LocalEndPoint is incorrect");

                    if (sock.RemoteEndPoint == null)
                        throw new Exception("RemoteEndPoint is null");
                    if (testSockets.socketClient.LocalEndPoint.ToString() !=
                        sock.RemoteEndPoint.ToString())
                        throw new Exception("RemoteEndPoint is incorrect");

                    cBytes = sock.Available;

                    if (cBytes != testSockets.bufSend.Length)
                        throw new Exception("Send failed, wrong length");

                    cBytes = sock.Receive(testSockets.bufReceive);
                }

                testSockets.AssertDataReceived(cBytes);
            }
            catch (SocketException e)
            {
                Log.Comment("Caught exception: " + e.Message);
                Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                    Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                testResult = false;
            }
            finally
            {
                if (testSockets != null)
                {
                    testSockets.TearDown();
                    testSockets = null;
                }
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:69,代码来源:SocketTests.cs

示例9: SocketsEnums12_SON_AcceptConnection

        public MFTestResults SocketsEnums12_SON_AcceptConnection()
        {
            /// <summary>
            /// 1. Starts a server socket listening for TCP
            /// 2. Verifies that AcceptConnection is correct before and after
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                byte[] buf = new byte[4];
                int number;

                SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
                testSockets.Startup(0, 0);
                testSockets.socketServer.GetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.AcceptConnection, buf );
                number = (int)buf[0] + (int)(buf[1]<<8) + (int)(buf[2]<<16) + (int)(buf[3]<<24);
                testResult &= (number == 0);
                testSockets.socketServer.Listen(1);
                
                testSockets.socketServer.GetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.AcceptConnection, buf );
                number = (int)buf[0] + (int)(buf[1]<<8) + (int)(buf[2]<<16) + (int)(buf[3]<<24);
                
                testResult &= (number != 0);
                testSockets.TearDown();
                testSockets = null;

            }
            catch (System.Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                    Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:39,代码来源:SocketsEnumsTests.cs

示例10: SocketsEnums9_SocketOptionLevel

        public MFTestResults SocketsEnums9_SocketOptionLevel()
        {
            /// <summary>
            /// 1. Tests that Set and GetSocketOption can be called using each member of 
            /// SocketOptionLevel
            /// 
            /// TODO: Fix Docs for (...Byte[])
            /// </summary>
            ///
            bool isAnyCatch = false; try
            {
                SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

                try
                {
                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.Tcp,
                        SocketOptionName.NoDelay, false);
                    if (0 != (int)testSockets.socketClient.GetSocketOption(
                        SocketOptionLevel.Tcp, SocketOptionName.NoDelay))
                        throw new System.Exception("SocketOptionLevel.Tcp failed");

                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.Socket,
                        SocketOptionName.Linger, true);
                    if (0 == (int)testSockets.socketClient.GetSocketOption(
                        SocketOptionLevel.Socket, SocketOptionName.Linger))
                        throw new System.Exception("SocketOptionLevel.Socket failed");

                    testSockets.socketClient.SetSocketOption(SocketOptionLevel.IP,
                        SocketOptionName.DontFragment, true);
                    if (0 == (int)testSockets.socketClient.GetSocketOption(
                        SocketOptionLevel.IP, SocketOptionName.DontFragment))
                        throw new System.Exception("SocketOptionLevel.IP failed");

                    if ((int)testSockets.socketClient.GetSocketOption(
                        SocketOptionLevel.Socket, SocketOptionName.Linger) != 1)
                        throw new System.Exception(
                            "GetSocketOption with Level and Name got wrong data");

                    byte[] lingerBytes = new byte[] { 0, 0, 0, 0 };
                    testSockets.socketClient.GetSocketOption(
                        SocketOptionLevel.Socket, SocketOptionName.Linger, lingerBytes);
                    if (!SocketTools.ArrayEquals(lingerBytes, new byte[] { 1, 0, 0, 0 }))
                        throw new System.Exception("GetSocketOption with Level,"
                            + " Name and ByteArray got wrong data");

                    testSockets.Startup(0, 0);
                    testSockets.socketServer.Listen(1);
                    testSockets.socketClient.Connect(testSockets.epServer);
                    testSockets.socketClient.Send(testSockets.bufSend);

                    int cBytes = 0;
                    using (Socket sock = testSockets.socketServer.Accept())
                    {
                        Thread.Sleep(500);
                        cBytes = sock.Available;
                        cBytes = sock.Receive(testSockets.bufReceive);
                    }
                    testSockets.AssertDataReceived(cBytes);
                }
                catch (SocketException e)
                {
                    isAnyCatch = true;
                    Log.Comment("System.Exception caught: " + e.Message + " " + e.ErrorCode);
                }
            finally
            {
                testSockets.TearDown();
            }

            }
            catch (System.Exception e)
            {
                isAnyCatch = true;
                Log.Comment("System.Exception caught: " + e.Message);
            }

            return (!isAnyCatch ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:78,代码来源:SocketsEnumsTests.cs

示例11: SocketExceptionTest20_OperationNotSupported

        public MFTestResults SocketExceptionTest20_OperationNotSupported()
        {
            /// <summary>
            /// 1. Causes a OperationNotSupported error
            /// </summary>
            ///
            bool isCorrectCatch = false;
            bool isAnyCatch = false;
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
            try
            {
                try
                {
                    testSockets.Startup(0, 0);

                    testSockets.socketServer.Listen(1);
                    testSockets.socketClient.Connect(testSockets.epServer);
                    testSockets.socketClient.Send(testSockets.bufSend);

                    using (Socket sock = testSockets.socketServer.Accept())
                    {
                        sock.Receive(testSockets.bufReceive, SocketFlags.DontRoute);
                    }

                    isCorrectCatch = true;
                }
                catch (SocketException)
                {
                    isCorrectCatch = true;
                    isAnyCatch = true;
                }
            }
            catch (System.Exception e)
            {
                isAnyCatch = true;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            if (!isAnyCatch)
            {
                Log.Comment("No exception caught");
            }
            testSockets.TearDown();
            testSockets = null;
            return (isCorrectCatch ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:45,代码来源:SocketExceptionTests.cs

示例12: SocketExceptionTest19_ProtocolOption

 public MFTestResults SocketExceptionTest19_ProtocolOption()
 {
     /// <summary>
     /// 1. Causes a ProtocolOption error
     /// </summary>
     ///
     bool isCorrectCatch = false;
     bool isAnyCatch = false;
     SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
     try
     {
         try
         {
             testSockets.Startup(0, 0);
             testSockets.socketClient.GetSocketOption(SocketOptionLevel.IP,
                 SocketOptionName.Linger);
         }
         catch (SocketException)
         {
             isCorrectCatch = true;
             isAnyCatch = true;
         }
     }
     catch (System.Exception e)
     {
         isAnyCatch = true;
         Log.Comment("Incorrect exception caught: " + e.Message);
     }
     if (!isAnyCatch)
     {
         Log.Comment("No exception caught");
     }
     testSockets.TearDown();
     testSockets = null;
     return (isCorrectCatch ? MFTestResults.Pass : MFTestResults.Fail);
 }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:36,代码来源:SocketExceptionTests.cs

示例13: SocketExceptionTest14_AddressNotAvailable

        public MFTestResults SocketExceptionTest14_AddressNotAvailable()
        {
            /// <summary>
            /// 1. Causes a AddressNotAvailable error
            /// Due to loopback this method causes an InvalidArgument
            /// SocketException erroneously
            /// </summary>
            ///
            bool isCorrectCatch = false;
            bool isAnyCatch = false;
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
            try
            {
                try
                {
                    int clientPort = SocketTools.nextPort;
                    int serverPort = SocketTools.nextPort;
                    int tempPort = clientPort;
                    testSockets.Startup(clientPort, serverPort);

                    testSockets.socketClient.Bind(new IPEndPoint(new IPAddress(SocketTools.DottedDecimalToIp((byte)192, (byte)168, (byte)192, (byte)168)), tempPort));
                }
                catch (SocketException)
                {
                    isCorrectCatch = true;
                    isAnyCatch = true;
                }
            }
            catch (System.Exception e)
            {
                isAnyCatch = true;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            finally
            {
                testSockets.TearDown();
            }
            if (!isAnyCatch)
            {
                Log.Comment("No exception caught");
            }
            return (isCorrectCatch ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:43,代码来源:SocketExceptionTests.cs

示例14: SocketExceptionTest13_InvalidArgument

 public MFTestResults SocketExceptionTest13_InvalidArgument()
 {
     /// <summary>
     /// 1. Causes a InvalidArgument error
     /// </summary>
     ///
     bool isCorrectCatch = false;
     bool isAnyCatch = false;
     SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
     try
     {
         try
         {
             int clientPort = SocketTools.nextPort;
             int serverPort = SocketTools.nextPort;
             int tempPort = clientPort;
             testSockets.Startup(clientPort, serverPort);
             testSockets.socketServer.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.Broadcast, true);
         }
         catch (SocketException)
         {
             isCorrectCatch = true;
             isAnyCatch = true;
         }
     }
     catch (System.Exception e)
     {
         isAnyCatch = true;
         Log.Comment("Incorrect exception caught: " + e.Message);
     }
     finally
     {
         testSockets.TearDown();
     }
     if (!isAnyCatch)
     {
         Log.Comment("No exception caught");
     }
     return (isCorrectCatch ? MFTestResults.Pass : MFTestResults.Fail);
 }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:40,代码来源:SocketExceptionTests.cs

示例15: SocketExceptionTest12_NotConnected

 public MFTestResults SocketExceptionTest12_NotConnected()
 {
     /// <summary>
     /// 1. Causes a NotConnected error
     /// </summary>
     ///
     bool isCorrectCatch = false;
     bool isAnyCatch = false;
     SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
     try
     {
         try
         {
             testSockets.Startup(0, 0);
             Socket socketTemp = new Socket(AddressFamily.InterNetwork,
                 SocketType.Stream, ProtocolType.Tcp);
             socketTemp.Bind(testSockets.socketServer.RemoteEndPoint);
             socketTemp.Send(new byte[2]);
         }
         catch (SocketException)
         {
             isCorrectCatch = true;
             isAnyCatch = true;
         }
     }
     catch (System.Exception e)
     {
         isAnyCatch = true;
         Log.Comment("Incorrect exception caught: " + e.Message);
     }
     finally
     {
         testSockets.TearDown();
     }
     if (!isAnyCatch)
     {
         Log.Comment("No exception caught");
     }
     return (isCorrectCatch ? MFTestResults.Pass : MFTestResults.Fail);
 }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:40,代码来源:SocketExceptionTests.cs


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