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


C# Sockets.SocketException类代码示例

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


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

示例1: OnDisconnect

        private void OnDisconnect(/*OPTIONAL*/ SocketException socketException)
        {
            // This handles disconnects if, for example, the app exits

            // If we have any waiting operations, we want to abort them
            List<WaitingOperationDescriptor> operationsToAbort = null;
            lock (_waitingOperations)
            {
                operationsToAbort = new List<WaitingOperationDescriptor>(_waitingOperations.Values);
                _waitingOperations.Clear();
            }
            foreach (var operation in operationsToAbort)
            {
                if (socketException == null)
                {
                    operation.Abort();
                }
                else
                {
                    operation.OnSocketError(socketException);
                }
            }

            // Otherwise just drop the connection
        }
开发者ID:lsgxeva,项目名称:MIEngine,代码行数:25,代码来源:Jdwp.cs

示例2: ConvertTransferException

 /// <summary>
 /// The Channel layer normalizes exceptions thrown by the underlying networking implementations
 /// into subclasses of CommunicationException, so that Channels can be used polymorphically from
 /// an exception handling perspective.
 /// </summary>
 internal static CommunicationException ConvertTransferException(SocketException socketException)
 {
     return new CommunicationException(
         string.Format(CultureInfo.CurrentCulture, 
         "A Udp error ({0}: {1}) occurred while transmitting data.", socketException.ErrorCode, socketException.Message), 
         socketException);
 }
开发者ID:ssickles,项目名称:archive,代码行数:12,代码来源:UdpChannelHelpers.cs

示例3: IsConnectionAbortedByTheOtherSide

        /// <summary>
        /// Determines if the exception thrown is a <see cref="SocketException"/> meaning that the connection was closed by the other side.
        /// </summary>
        public static bool IsConnectionAbortedByTheOtherSide(SocketException socketEx)
        {
            if (socketEx == null)
                throw new ArgumentNullException("socketEx");

            return ConnectionClosedErrors.Contains(socketEx.SocketErrorCode);
        }
开发者ID:knocte,项目名称:Fos,代码行数:10,代码来源:SocketHelper.cs

示例4: Complete

        void Complete(SocketAsyncEventArgs e, bool completeSynchronously)
        {
            TransportBase transport = null;
            Exception exception = null;
            if (e.SocketError != SocketError.Success)
            {
                exception = new SocketException((int)e.SocketError);
                if (e.AcceptSocket != null)
                {
                    e.AcceptSocket.Close(0);
                }
            }
            else
            {
                Fx.Assert(e.AcceptSocket != null, "Must have a valid socket accepted.");
                transport = new TcpTransport(e.AcceptSocket, this.transportSettings);
                transport.Open();
            }

            e.Dispose();
            this.callbackArgs.CompletedSynchronously = completeSynchronously;
            this.callbackArgs.Exception = exception;
            this.callbackArgs.Transport = transport;

            if (!completeSynchronously)
            {
                this.callbackArgs.CompletedCallback(this.callbackArgs);
            }
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:29,代码来源:TcpTransportInitiator.cs

示例5: CreateSocket

        public static unsafe SafeCloseSocket CreateSocket(SocketInformation socketInformation, out AddressFamily addressFamily, out SocketType socketType, out ProtocolType protocolType)
        {
            SafeCloseSocket handle;
            Interop.Winsock.WSAPROTOCOL_INFO protocolInfo;

            fixed (byte* pinnedBuffer = socketInformation.ProtocolInformation)
            {
                handle = SafeCloseSocket.CreateWSASocket(pinnedBuffer);
                protocolInfo = (Interop.Winsock.WSAPROTOCOL_INFO)Marshal.PtrToStructure<Interop.Winsock.WSAPROTOCOL_INFO>((IntPtr)pinnedBuffer);
            }

            if (handle.IsInvalid)
            {
                SocketException e = new SocketException();
                if (e.SocketErrorCode == SocketError.InvalidArgument)
                {
                    throw new ArgumentException(SR.net_sockets_invalid_socketinformation, "socketInformation");
                }
                else
                {
                    throw e;
                }
            }

            addressFamily = protocolInfo.iAddressFamily;
            socketType = (SocketType)protocolInfo.iSocketType;
            protocolType = (ProtocolType)protocolInfo.iProtocol;
            return handle;
        }
开发者ID:vbouret,项目名称:corefx,代码行数:29,代码来源:SocketPal.Windows.cs

示例6: IsTimeoutException

    bool IsTimeoutException(SocketException e)
    {
#if CF
       return (e.NativeErrorCode == 10060);
#else
      return (e.SocketErrorCode == SocketError.TimedOut);
#endif
    }
开发者ID:luguandao,项目名称:MySql.Data,代码行数:8,代码来源:MyNetworkStream.cs

示例7: IsWouldBlockException

    bool IsWouldBlockException(SocketException e)
    {
#if CF
      return (e.NativeErrorCode == 10035);
#else
      return (e.SocketErrorCode == SocketError.WouldBlock);
#endif
    }
开发者ID:luguandao,项目名称:MySql.Data,代码行数:8,代码来源:MyNetworkStream.cs

示例8: Parse

        internal static IPAddress Parse(string ipString, bool tryParse)
        {
            if (ipString == null)
            {
                if (tryParse)
                {
                    return null;
                }
                throw new ArgumentNullException("ipString");
            }

            uint error = 0;

            // IPv6 Changes: Detect probable IPv6 addresses and use separate parse method.
            if (ipString.IndexOf(':') != -1)
            {
                // If the address string contains the colon character
                // then it can only be an IPv6 address. Use a separate
                // parse method to unpick it all. Note: we don't support
                // port specification at the end of address and so can
                // make this decision.
                uint scope;
                byte[] bytes = new byte[IPAddressParserStatics.IPv6AddressBytes];
                error = IPAddressPal.Ipv6StringToAddress(ipString, bytes, out scope);

                if (error == IPAddressPal.SuccessErrorCode)
                {
                    // AppCompat: .Net 4.5 ignores a correct port if the address was specified in brackets.
                    // Will still throw for an incorrect port.
                    return new IPAddress(bytes, (long)scope);
                }
            }
            else
            {
                ushort port;
                byte[] bytes = new byte[IPAddressParserStatics.IPv4AddressBytes];
                error = IPAddressPal.Ipv4StringToAddress(ipString, bytes, out port);

                if (error == IPAddressPal.SuccessErrorCode)
                {
                    if (port != 0)
                    {
                        throw new FormatException(SR.dns_bad_ip_address);
                    }

                    return new IPAddress(bytes);
                }
            }

            if (tryParse)
            {
                return null;
            }

            Exception e = new SocketException(IPAddressPal.GetSocketErrorForErrorCode(error), error);
            throw new FormatException(SR.dns_bad_ip_address, e);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:57,代码来源:IPAddressParser.cs

示例9: initialize

        public int initialize()
        {
            if(_state == StateNeedConnect)
            {
                _state = StateConnectPending;
                return SocketOperation.Connect;
            }
            else if(_state <= StateConnectPending)
            {
                try
                {
#if ICE_SOCKET_ASYNC_API
                    if(_writeEventArgs.SocketError != SocketError.Success)
                    {
                        SocketException ex = new SocketException((int)_writeEventArgs.SocketError);
                        if(Network.connectionRefused(ex))
                        {
                            throw new Ice.ConnectionRefusedException(ex);
                        }
                        else
                        {
                            throw new Ice.ConnectFailedException(ex);
                        }
                    }
#else
                    Network.doFinishConnectAsync(_fd, _writeResult);
                    _writeResult = null;
#endif
                    _state = StateConnected;
                    _desc = Network.fdToString(_fd);
                }
                catch(Ice.LocalException ex)
                {
                    if(_traceLevels.network >= 2)
                    {
                        System.Text.StringBuilder s = new System.Text.StringBuilder();
                        s.Append("failed to establish tcp connection\n");
                        s.Append(Network.fdLocalAddressToString(_fd));
                        Debug.Assert(_addr != null);
                        s.Append("\nremote address = " + _addr.ToString() + "\n");
                        s.Append(ex.ToString());
                        _logger.trace(_traceLevels.networkCat, s.ToString());
                    }
                    throw;
                }

                if(_traceLevels.network >= 1)
                {
                    string s = "tcp connection established\n" + _desc;
                    _logger.trace(_traceLevels.networkCat, s);
                }
            }
            Debug.Assert(_state == StateConnected);
            return SocketOperation.None;
        }
开发者ID:sbesson,项目名称:zeroc-ice,代码行数:55,代码来源:TcpTransceiver.cs

示例10: HandleDnsLookupError

 static ErrorType HandleDnsLookupError( string context, SocketException se )
 {
     switch( se.SocketErrorCode ) {
     case SocketError.HostNotFound:
     case SocketError.NoData:
         return ErrorType.PermanentKnown;
     default:
         Debug.WriteLine( string.Format( "WARNING: Unexpected SocketException with SocketErrorCode=={0} in {1}", Enum.GetName(typeof(SocketError),se.SocketErrorCode), context ) );
         return ErrorType.TemporaryUnknown;
     }
 }
开发者ID:jovan-s,项目名称:LoggingMonkey,代码行数:11,代码来源:DnsCache.cs

示例11: ValidateAsyncResult

        protected bool ValidateAsyncResult(SocketAsyncEventArgs e)
        {
            if (e.SocketError != SocketError.Success)
            {
                var socketException = new SocketException((int)e.SocketError);
                OnCompleted(new ProxyEventArgs(new Exception(socketException.Message, socketException)));
                return false;
            }

            return true;
        }
开发者ID:ChuckFork,项目名称:SuperSocket.ClientEngine,代码行数:11,代码来源:ProxyConnectorBase.cs

示例12: ServerMockReceivedEventArgs

 internal ServerMockReceivedEventArgs( SocketAsyncEventArgs context )
 {
     this._context = context;
     if ( context.SocketError != SocketError.Success )
     {
         this._socketException = new SocketException( ( int )context.SocketError );
     }
     else
     {
         this._socketException = null;
     }
 }
开发者ID:yfakariya,项目名称:msgpack-rpc,代码行数:12,代码来源:ServerMockReceivedEventArgs.cs

示例13: ConvertListenException

 public static Exception ConvertListenException(SocketException socketException, IPEndPoint localEndpoint)
 {
     if (socketException.ErrorCode == 6)
     {
         return new CommunicationObjectAbortedException(socketException.Message, socketException);
     }
     if (socketException.ErrorCode == 0x2740)
     {
         return new AddressAlreadyInUseException(System.ServiceModel.SR.GetString("TcpAddressInUse", new object[] { localEndpoint.ToString() }), socketException);
     }
     return new CommunicationException(System.ServiceModel.SR.GetString("TcpListenError", new object[] { socketException.ErrorCode, socketException.Message, localEndpoint.ToString() }), socketException);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:SocketConnectionListener.cs

示例14: connect

        public int connect(Buffer readBuffer, Buffer writeBuffer, ref bool moreData)
        {
            if(_state == StateNeedConnect)
            {
                _state = StateConnectPending;
                return SocketOperation.Connect;
            }
            else if(_state <= StateConnectPending)
            {
#if ICE_SOCKET_ASYNC_API
                if(_writeEventArgs.SocketError != SocketError.Success)
                {
                    SocketException ex = new SocketException((int)_writeEventArgs.SocketError);
                    if(Network.connectionRefused(ex))
                    {
                        throw new Ice.ConnectionRefusedException(ex);
                    }
                    else
                    {
                        throw new Ice.ConnectFailedException(ex);
                    }
                }
#else
                Network.doFinishConnectAsync(_fd, _writeResult);
                _writeResult = null;
#endif
                _desc = Network.fdToString(_fd, _proxy, _addr);
                _state = _proxy != null ? StateProxyWrite : StateConnected;
            }

            if(_state == StateProxyWrite)
            {
                _proxy.beginWrite(_addr, writeBuffer);
                return SocketOperation.Write;
            }
            else if(_state == StateProxyRead)
            {
                _proxy.beginRead(readBuffer);
                return SocketOperation.Read;
            }
            else if(_state == StateProxyConnected)
            {
                _proxy.finish(readBuffer, writeBuffer);

                readBuffer.clear();
                writeBuffer.clear();

                _state = StateConnected;
            }

            Debug.Assert(_state == StateConnected);
            return SocketOperation.None;
        }
开发者ID:joshmoore,项目名称:ice,代码行数:53,代码来源:StreamSocket.cs

示例15: ThrowServerException

        public static void ThrowServerException(SocketException e, ServerContext serverContext = null)
        {
            string ipAddress = serverContext != null ? serverContext.IPAddress.ToString() : "unknown";
            string port = serverContext != null ? serverContext.Port.ToString() : "-";

            if (ipAddress.Equals("0.0.0.0")) ipAddress = "any";

            if (e.Message.StartsWith("Only one usage of each socket address"))
                throw new ServerException(
                    string.Format(
                        "Can't bind to socket on port {0} for IP addresses ({1}) because it is already in use (is the server already running?)",
                        port, ipAddress), e);

            throw e;
        }
开发者ID:subfuzion,项目名称:gsDesign,代码行数:15,代码来源:ServerException.cs


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