Example #1
0
        public void SocketExceptionTest19_ProtocolOption()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

            Assert.Throws(typeof(SocketException), () =>
            {
                testSockets.Startup(0, 0);
                testSockets.socketClient.GetSocketOption(SocketOptionLevel.IP,
                                                         SocketOptionName.Linger);
            });
            testSockets.TearDown();
            testSockets = null;
        }
Example #2
0
        public void SocketExceptionTest18_Fault()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

            Assert.Throws(typeof(SocketException), () =>
            {
                testSockets.socketClient.SetSocketOption(SocketOptionLevel.Socket,
                                                         SocketOptionName.Linger, new byte[] { (byte)0 });
                testSockets.Startup(0, 0);
            });

            testSockets.TearDown();
        }
Example #3
0
        public void SocketExceptionTest6_IsConnected()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

            Assert.Throws(typeof(SocketException), () =>
            {
                testSockets.Startup(0, 0);
                testSockets.socketServer.Listen(1);
                testSockets.socketClient.Connect(testSockets.epServer);
                testSockets.socketClient.Connect(testSockets.epServer);
            });

            testSockets.TearDown();
        }
Example #4
0
        public void SocketExceptionTest13_InvalidArgument()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

            Assert.Throws(typeof(SocketException), () =>
            {
                int clientPort = SocketTools.nextPort;
                int serverPort = SocketTools.nextPort;
                int tempPort   = clientPort;
                testSockets.Startup(clientPort, serverPort);
                testSockets.socketServer.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.Broadcast, true);
            });

            testSockets.TearDown();
        }
Example #5
0
        public void SocketExceptionTest12_NotConnected()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

            Assert.Throws(typeof(SocketException), () =>
            {
                testSockets.Startup(0, 0);
                Socket socketTemp = new Socket(AddressFamily.InterNetwork,
                                               SocketType.Stream, ProtocolType.Tcp);
                socketTemp.Bind(testSockets.socketServer.RemoteEndPoint);
                socketTemp.Send(new byte[2]);
            });

            testSockets.TearDown();
        }
Example #6
0
        public void SocketExceptionTest14_AddressNotAvailable()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

            Assert.Throws(typeof(SocketException), () =>
            {
                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));
            });

            testSockets.TearDown();
        }
Example #7
0
        public void SocketExceptionTest11_AccessDenied()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Udp, SocketType.Dgram);

            Assert.Throws(typeof(SocketException), () =>
            {
                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);
            });

            testSockets.TearDown();
        }
Example #8
0
        public void SocketExceptionTest20_OperationNotSupported()
        {
            SocketPair testSockets = new SocketPair(ProtocolType.Tcp, SocketType.Stream);

            Assert.Throws(typeof(SocketException), () =>
            {
                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);
                }
            });
            testSockets.TearDown();
            testSockets = null;
        }