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

C# Tests.SocketPair类代码示例

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

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



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


示例3: 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


示例4: SocketTest2_BasicUDP

        public MFTestResults SocketTest2_BasicUDP()
        {
            /// <summary>
            /// 1. Starts a server socket listening for UDP
            /// 2. Starts a client socket sending UDP packets
            /// 3. Verifies that data can be correctly sent and recieved
            /// </summary>
            ///
            bool testResult = true;
            SocketPair testSockets = null;
            try
            {
                testSockets = new SocketPair(ProtocolType.Udp, SocketType.Dgram);
                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");
            }
            catch (SocketException e)
            {
                if (e.ErrorCode == 10047)
                {
                    Log.Comment("Address family not supported by protocol family.");
                    Log.Comment("This exception is thrown by the device driver that doesnt' implement Loopback for UDP");
                }
                else
                {
                    testResult = false;
                    Log.Comment("Fail for any other error codes that we don't know about");
                }
            }
            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,代码行数:58,代码来源:SocketTests.cs


示例5: SocketTest13_DPWSOptions

        public MFTestResults SocketTest13_DPWSOptions()
        {
            /// <summary>
            /// 1. Starts a server socket listening for UDP
            /// 2. Starts a client socket sending UDP packets
            /// 3. Verifies that data can be correctly sent and recieved
            /// </summary>
            ///

            //don't run on the emulator since this isn't supported
            if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
                return MFTestResults.Skip;

            bool testResult = true;
            try
            {
                SocketPair testSockets = new SocketPair(ProtocolType.Udp, SocketType.Dgram);

                NetworkInterface[] inter = NetworkInterface.GetAllNetworkInterfaces();

                IPAddress localAddress = SocketTools.ParseAddress(inter[0].IPAddress);
                try
                {
                    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.AddMembership, 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
                {
                    byte [] bytes = localAddress.GetAddressBytes();
                    // given the address change it to what SetSocketOption needs
                    testSockets.socketClient.SetSocketOption(
                        SocketOptionLevel.IP,
                        SocketOptionName.MulticastInterface,
                        bytes);
                }
                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.IP,
                        SocketOptionName.DontFragment, true);
//.........这里部分代码省略.........
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,代码来源:SocketTests.cs


示例6: 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


示例7: SocketsEnums11_SocketOptionName_Debug_UDP

        public MFTestResults SocketsEnums11_SocketOptionName_Debug_UDP()
        {
            //don't run this on emulator since its not supported.
            if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
                return MFTestResults.Skip;

            SocketPair testSockets = new SocketPair(ProtocolType.Udp, SocketType.Dgram);
            Log.Comment("Testing Debug with UDP");
            bool testResult = TestSocketOption(testSockets, SocketOptionLevel.Socket, 
                SocketOptionName.Debug, boolData, false);
            testSockets.TearDown();
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:13,代码来源:SocketsEnumsTests.cs


示例8: SocketsEnums11_SocketOptionName_AddSourceMembership_UDP

        public MFTestResults SocketsEnums11_SocketOptionName_AddSourceMembership_UDP()
        {
            //don't run this on emulator since its not supported.
            if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
                return MFTestResults.Skip;

            NetworkInterface[] inter = NetworkInterface.GetAllNetworkInterfaces();
            IPAddress localAddress = SocketTools.ParseAddress(inter[0].IPAddress);
            byte[] local = localAddress.GetAddressBytes();
            byte[] multicastOpt = new byte[] {    224,      100,        1,        1,
                                                          local[0], local[1], local[2], local[3]};

            SocketPair testSockets = new SocketPair(ProtocolType.Udp, SocketType.Dgram);
            Log.Comment("Testing AddSourceMembership with UDP");
            bool testResult = TestSocketOption(testSockets, SocketOptionLevel.IP, 
                SocketOptionName.AddSourceMembership, multicastOpt, false);
            testSockets.TearDown();
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:19,代码来源:SocketsEnumsTests.cs


示例9: SocketsEnums11_SocketOptionName_DropSourceMembership_TCP

        public MFTestResults SocketsEnums11_SocketOptionName_DropSourceMembership_TCP()
        {
            NetworkInterface[] inter = NetworkInterface.GetAllNetworkInterfaces();
            IPAddress localAddress = SocketTools.ParseAddress(inter[0].IPAddress);
            byte[] local = localAddress.GetAddressBytes();
            byte[] multicastOpt = new byte[] {    224,      100,        1,        1,
                                                          local[0], local[1], local[2], local[3]};

            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
            Log.Comment("Testing DropSourceMembership with TCP");
            bool testResult = TestSocketOption(testSockets, SocketOptionLevel.IP, 
                SocketOptionName.DropSourceMembership, multicastOpt, false);
            testSockets.TearDown();
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:15,代码来源:SocketsEnumsTests.cs


示例10: SocketsEnums11_SocketOptionName_DontFragment_TCP

 public MFTestResults SocketsEnums11_SocketOptionName_DontFragment_TCP()
 {
     SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
     Log.Comment("Testing DontFragment with TCP");
     bool testResult = TestSocketOption(testSockets, SocketOptionLevel.IP, 
         SocketOptionName.DontFragment, boolData, true);
     testSockets.TearDown();
     return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
 }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:9,代码来源:SocketsEnumsTests.cs


示例11: TestSocketOptionSetOnly

        private bool TestSocketOptionSetOnly(SocketPair testSockets, 
            SocketOptionLevel optionLevel,
             SocketOptionName optionName, Object data, bool isSupported)
        {
            try
            {
                Log.Comment("Option is only valid for Set");
                string typeStr = data.GetType().ToString();
                switch (typeStr)
                {
                    case "System.Boolean":
                        testSockets.socketClient.SetSocketOption(optionLevel, 
                            optionName, (bool)data);
                        break;
                    case "System.Int32":
                        testSockets.socketClient.SetSocketOption(optionLevel, 
                            optionName, (int)data);
                        break;
                    case "System.Byte[]":
                        testSockets.socketClient.SetSocketOption(optionLevel, 
                            optionName, (byte[])data);
                        break;
                    default:
                        throw new Exception("Test Error, cannot set socket option with that type");
                }
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                {
                    Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                    if (!isSupported && (((SocketException)e).ErrorCode == (int)SocketError.ProtocolOption || 
                        ((SocketException)e).ErrorCode == (int)SocketError.AddressFamilyNotSupported || 
                        ((SocketException)e).ErrorCode == (int)SocketError.InvalidArgument || 
                        ((SocketException)e).ErrorCode == (int)SocketError.AddressNotAvailable))
                    {
                        Log.Comment("Non-supported option graceful fail");
                        return true;
                    }
                    else if (isSupported && ((SocketException)e).ErrorCode == (int)SocketError.ProtocolOption)
                    {
                        Log.Comment(
                            "Supported option graceful fail, this option needs implementation");
                        return true;
                    }
                    else if (!isSupported && (((SocketException)e).ErrorCode == (int)SocketError.ProtocolOption || 
                        ((SocketException)e).ErrorCode == (int)SocketError.InvalidArgument || 
                        ((SocketException)e).ErrorCode == (int)SocketError.AddressNotAvailable))
                    {
                        Log.Comment("Non-supported option failed with bad errorcode, " +
                            "should be 10042 or 10022");
                    }
                }
                Log.Comment("SocketOption FAILED");
                return false;
            }

            if (!isSupported)
            {
                Log.Comment("This option is not supported.  Should throw an exception");
                return true;
            }

            Log.Comment("SocketOption succeeded");
            return true;
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:67,代码来源:SocketsEnumsTests.cs


示例12: TestSocketOption

        private bool TestSocketOption(SocketPair testSockets, SocketOptionLevel optionLevel, 
             SocketOptionName optionName, Object data, bool isSupported)
        {
            try
            {
                string typeStr = data.GetType().ToString();
                switch (typeStr)
                {
                    case "System.Boolean":
                        Log.Comment("First set");
                        testSockets.socketClient.SetSocketOption(optionLevel, optionName, 
                            (bool)data);
                        Log.Comment("First get"); 
                        if (((int)testSockets.socketClient.GetSocketOption(optionLevel, 
                            optionName) == 1) != (bool)data)
                            throw new Exception("Got wrong data after first Set");
                        Log.Comment("Second set"); 
                        testSockets.socketClient.SetSocketOption(optionLevel, optionName, 
                            !(bool)data);
                        Log.Comment("Second get");
                        if (((int)testSockets.socketClient.GetSocketOption(optionLevel, 
                            optionName) == 1) != !(bool)data)
                            throw new Exception("Got wrong data after second Set");
                        break;
                    case "System.Int32":
                        Log.Comment("First set");
                        testSockets.socketClient.SetSocketOption(optionLevel, optionName, 
                            (int)data);
                        Log.Comment("First get");
                        if ((int)testSockets.socketClient.GetSocketOption(optionLevel, 
                            optionName) != (int)data)
                            throw new Exception("Got wrong data after first Set");
                        Log.Comment("Second set");
                        testSockets.socketClient.SetSocketOption(optionLevel, optionName, 
                            (int)data - 1);
                        Log.Comment("Second get");
                        if ((int)testSockets.socketClient.GetSocketOption(optionLevel, 
                            optionName) != (int)data - 1)
                            throw new Exception("Got wrong data after second Set");
                        break;
                    case "System.Byte[]":
                        Log.Comment("First set");
                        byte[] result = new byte[((byte[])data).Length];
                        testSockets.socketClient.SetSocketOption(optionLevel, optionName, 
                            (byte[])data);
                        testSockets.socketClient.GetSocketOption(optionLevel, optionName, 
                            result) ;
                        Log.Comment("First get");
                        if (!SocketTools.ArrayEquals(result, (byte[])data))
                            throw new Exception("Got wrong data after first Set");

                        //Decrement first byte of data
                        ((byte[])data)[0]--;

                        Log.Comment("Second set");
                        testSockets.socketClient.SetSocketOption(optionLevel, optionName, 
                            (byte[])data); 
                        testSockets.socketClient.GetSocketOption(optionLevel, optionName, 
                            result);
                        Log.Comment("Second get");
                        if (!SocketTools.ArrayEquals(result, (byte[])data))
                            throw new Exception("Got wrong data after second Set");
                        break;
                    default:
                        throw new Exception("Test Error, cannot set socket option with that type");
                }
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                if (e.GetType() == Type.GetType("System.Net.Sockets.SocketException"))
                {
                    Log.Comment("ErrorCode: " + ((SocketException)e).ErrorCode);
                    if (!isSupported && (((SocketException)e).ErrorCode == (int)SocketError.ProtocolOption ||
                        ((SocketException)e).ErrorCode == (int)SocketError.AddressFamilyNotSupported ||
                        ((SocketException)e).ErrorCode == (int)SocketError.InvalidArgument ||
                        ((SocketException)e).ErrorCode == (int)SocketError.AddressNotAvailable))
                    {
                        Log.Comment("Non-supported option graceful fail");
                        return true;
                    }
                    else if (isSupported && ((SocketException)e).ErrorCode == (int)SocketError.ProtocolOption)
                    {
                        Log.Comment(
                            "Supported option graceful fail, this option needs implementation");
                        return true;
                    }
                    else if (!isSupported && (((SocketException)e).ErrorCode == (int)SocketError.ProtocolOption ||
                        ((SocketException)e).ErrorCode == (int)SocketError.InvalidArgument ||
                        ((SocketException)e).ErrorCode == (int)SocketError.AddressNotAvailable))
                    {
                        Log.Comment("Non-supported option failed with bad errorcode, " +
                            "should be 10042 or 10022");
                    }
                }
                Log.Comment("SocketOption FAILED");
                return false;
            }

            if (!isSupported)
//.........这里部分代码省略.........
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:101,代码来源:SocketsEnumsTests.cs


示例13: SocketsEnums15_SON_SendBuffer

        public MFTestResults SocketsEnums15_SON_SendBuffer()
        {
            /// <summary>
            /// 1. Sends a message of size SendBuffer
            /// 2. Verifies that it transferred correctly
            /// 1. Sends a message of size SendBuffer+1
            /// 2. Verifies that the correct exception is thrown
            /// </summary>
            ///
            bool testResult = true;
            byte[] buf = new byte[4];
            int number;
            try
            {
                int sendBufferValue1 = 1024;
                int sendBufferValue2 = 512;

                SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
                testSockets.socketClient.SetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sendBufferValue1);
                testSockets.socketClient.GetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.SendBuffer, buf);
                number = (int)buf[0] + (int)(buf[1]<<8) + (int)(buf[2]<<16) + (int)(buf[3]<<24);
                
                if(number != sendBufferValue1)
                        throw new System.Exception("ReceiveBuffer option was not set correctly");

                testSockets.socketClient.SetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sendBufferValue2);
                testSockets.socketClient.GetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.SendBuffer, buf);
                number = (int)buf[0] + (int)(buf[1]<<8) + (int)(buf[2]<<16) + (int)(buf[3]<<24);
                
                if(number != sendBufferValue2)
                        throw new System.Exception("ReceiveBuffer option was not set correctly");

                Log.Comment("ReceiveBuffer " + number.ToString() );
                   
                testSockets.Startup(0, 0);

                testSockets.bufSend    = new byte[number];
                testSockets.bufReceive = new byte[number];

                testSockets.socketServer.Listen(1);
                testSockets.socketClient.Connect(testSockets.epServer);
                int cBytes = testSockets.socketClient.Send(testSockets.bufSend);
                if (cBytes != testSockets.bufSend.Length)
                    throw new System.Exception("Send failed, wrong length");

                using (Socket sock = testSockets.socketServer.Accept())
                {
                    if (sock.LocalEndPoint == null)
                        throw new System.Exception("LocalEndPoint is null");

                    if (testSockets.socketServer.LocalEndPoint.ToString() != 
                        sock.LocalEndPoint.ToString())
                        throw new System.Exception("LocalEndPoint is incorrect");

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

                    //wait a second to ensure the socket is available
                    System.Threading.Thread.Sleep(1000);  

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

                    cBytes = sock.Receive(testSockets.bufReceive);
                }
                testSockets.AssertDataReceived(cBytes);
                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,代码行数:87,代码来源:SocketsEnumsTests.cs


示例14: SocketsEnums13_SON_Broadcast

        public MFTestResults SocketsEnums13_SON_Broadcast()
        {
            /// <summary>
            /// 1. Starts a UDP client broadcasting 
            /// 2. Verifies that Broadcast is correct before and after
            /// </summary>
            ///
            bool testResult = false;
            try
            {
                SocketPair testSockets1 = new SocketPair(ProtocolType.Udp, SocketType.Dgram);
                int clientPort1 = SocketTools.nextPort;
                int serverPort1 = SocketTools.nextPort;
                int tempPort1 = SocketTools.nextPort;
                IPEndPoint epBroadcast1 = new IPEndPoint(
                    SocketTools.DottedDecimalToIp(
                    (byte)255, (byte)255, (byte)255, (byte)255), tempPort1);

                Log.Comment("SetSocketOption socket, broadcast, false");
                testSockets1.socketClient.SetSocketOption(
                    SocketOptionLevel.Socket, SocketOptionName.Broadcast, false);

                try
                {
                    Log.Comment("SendTo epBroadcast1");
                    testSockets1.socketClient.SendTo(
                        new byte[] { 0x01, 0x02, 0x03 }, epBroadcast1);
                    Log.Comment("Error, this should never get displayed.  An exception should have been thrown.");
                }
                catch (SocketException e)
                {
                    Log.Comment("Error code: " + e.ErrorCode);
                    Log.Comment("Correctly threw exception trying to broadcast from socket that has had broadcast turned off.");
                    testResult = true;
                }
                catch (Exception e)
                {
                    Log.Comment("Incorrect exception thrown: " + e.Message);
                }
                finally
                {
                    Log.Comment("Tear down the socket");
                    testSockets1.TearDown();
                }
                //--//

                SocketPair testSockets2 = new SocketPair(ProtocolType.Udp, SocketType.Dgram);
                int clientPort2 = SocketTools.nextPort;
                int serverPort2 = SocketTools.nextPort;
                int tempPort2 = SocketTools.nextPort;
                IPEndPoint epBroadcast2 = new IPEndPoint(
                    SocketTools.DottedDecimalToIp(
                    (byte)255, (byte)255, (byte)255, (byte)255), tempPort2);

                Log.Comment("SetSocketOption socket, broadcast, true");
                testSockets2.socketClient.SetSocketOption(
                    SocketOptionLevel.Socket,SocketOptionName.Broadcast, true);

                try
                {
                    Log.Comment("SendTo epBroadcast1");
                    testSockets2.socketClient.SendTo(
                        new byte[] { 0x01, 0x02, 0x03 }, epBroadcast2);
                }
                catch (SocketException e)
                {
                    Log.Comment("Error code: " + e.ErrorCode);
                    if (e.ErrorCode == 10047)
                    {
                        Log.Comment("Some drivers do not like this option being set.  Allow them to throw this exception");
                        testResult &= true;
                    }
                    else
                    {
                        Log.Comment("Incorrectly threw exception trying to broadcast from socket that has had broadcast turned on.");
                        testResult = false;
                    }
                }
                catch (Exception e)
                {
                    Log.Comment("Incorrect exception thrown: " + e.Message);
                }
                finally
                {
                    Log.Comment("Tear down the socket");
                    testSockets2.TearDown();
                }
            }
            catch (SocketException e)
            {
                Log.Comment("SocketException ErrorCode: " + e.ErrorCode);
                if (e.ErrorCode == 10047)
                {
                    Log.Comment("Address family not supported by protocol family.");
                    Log.Comment("This exception is thrown by the device driver that doesnt' implement Loopback for UDP");
                }
                else
                {
                    Log.Comment("Fail for any other error codes that we don't know about");
                    testResult = false;
//.........这里部分代码省略.........
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:101,代码来源:SocketsEnumsTests.cs


示例15: SocketsEnums11_SocketOptionName_UseLoopback_TCP

 public MFTestResults SocketsEnums11_SocketOptionName_UseLoopback_TCP()
 {
     SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
     Log.Comment("Testing UseLoopback with TCP");
     bool testResult = TestSocketOption(testSockets, SocketOptionLevel.IP, 
         SocketOptionName.UseLoopback, boolData, false);
     testSockets.TearDown();
     return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
 }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:9,代码来源:SocketsEnumsTests.cs


示例16: SocketsEnums11_SocketOptionName_MulticastInterface_TCP

        public MFTestResults SocketsEnums11_SocketOptionName_MulticastInterface_TCP()
        {
            NetworkInterface[] inter = NetworkInterface.GetAllNetworkInterfaces();
            IPAddress localAddress = SocketTools.ParseAddress(inter[0].IPAddress);

            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);
            Log.Comment("Testing MulticastInterface with TCP");
            bool testResult = TestSocketOption(testSockets, SocketOptionLevel.IP, 
                SocketOptionName.MulticastInterface, localAddress.GetAddressBytes(), false);
            testSockets.TearDown();
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:12,代码来源:SocketsEnumsTests.cs


示例17: SocketsEnums11_SocketOptionName_AcceptConnection_UDP

 public MFTestResults SocketsEnums11_SocketOptionName_AcceptConnection_UDP()
 {
     SocketPair testSockets = new SocketPair(ProtocolType.Udp, SocketType.Dgram);
     Log.Comment("Testing AcceptConnection with UDP");
     bool testResult = TestSocketOption(testSockets, SocketOptionLevel.Socket, 
         SocketOptionName.AcceptConnection, boolData, false);
     testSockets.TearDown();
     return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
 }
开发者ID:adamlin1970,项目名称:NetmfSTM32,代码行数:9,代码来源:SocketsEnumsTests.cs

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# CorDebug.CorAppDomain类代码示例发布时间:2022-05-26
下一篇:
C# Tests.HttpServer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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