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

C# Sockets.SocketException类代码示例

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

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



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


示例16: IsDisconnected

 public static bool IsDisconnected(SocketException exception)
 {
     switch ((SocketError) exception.ErrorCode)
     {
         case SocketError.ConnectionAborted:
         case SocketError.ConnectionReset:
         case SocketError.Fault:
         case SocketError.NetworkReset:
         case SocketError.OperationAborted:
         case SocketError.Shutdown:
         case SocketError.SocketError:
         case SocketError.TimedOut:
             return true;
     }
     return false;
 }
开发者ID:ktj007,项目名称:mmo,代码行数:16,代码来源:SocketHelper.cs


示例17: IsSocketDisconnectedException

 public static bool IsSocketDisconnectedException(SocketException socketException)
 {
     var errorCode = socketException.SocketErrorCode;
     return errorCode == SocketError.NetworkDown ||
            errorCode == SocketError.NetworkReset ||
            errorCode == SocketError.NetworkUnreachable ||
            errorCode == SocketError.ConnectionAborted ||
            errorCode == SocketError.ConnectionReset ||
            errorCode == SocketError.HostNotFound ||
            errorCode == SocketError.HostUnreachable ||
            errorCode == SocketError.NotConnected ||
            errorCode == SocketError.Shutdown ||
            errorCode == SocketError.Disconnecting ||
            errorCode == SocketError.AddressNotAvailable ||
            errorCode == SocketError.TimedOut;
 }
开发者ID:KeithLee208,项目名称:ecommon,代码行数:16,代码来源:SocketUtils.cs


示例18: ValidateAsyncResult

        protected bool ValidateAsyncResult(SocketAsyncEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

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

            return true;
        }
开发者ID:adasescu,项目名称:cf-dotnet-sdk-1,代码行数:16,代码来源:ProxyConnectorBase.cs


示例19: 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.Dispose();
                }
            }
            else
            {
                try
                {
                    Fx.Assert(e.ConnectSocket != null, "Must have a valid socket accepted.");
                    e.ConnectSocket.NoDelay = true;
                    transport = new TcpTransport(e.ConnectSocket, this.transportSettings);
                    transport.Open();
                }
                catch (Exception exp)
                {
                    if (Fx.IsFatal(exp))
                    {
                        throw;
                    }

                    exception = exp;
                    if (transport != null)
                    {
                        transport.SafeClose();
                    }
                    transport = null;
                }
            }

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

            if (!completeSynchronously)
            {
                this.callbackArgs.CompletedCallback(this.callbackArgs);
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:47,代码来源:TcpTransportInitiator.cs


示例20: ShowError

        private static void ShowError(SocketException aSocketException)
        {
            String errorText;
            switch (aSocketException.ErrorCode)
            {
                case 10060:
                    errorText = ExceptionStrings.ErrorWsaETimedOut;
                    break;
                case 10061:
                    errorText = ExceptionStrings.ErrorWsaEConnRefused;
                    break;
                default:
                    errorText = Convert.ToString(aSocketException.ErrorCode) + "; " + aSocketException.Message;
                    break;
            }

            ShowError(errorText);
        }
开发者ID:BeL1kOFF,项目名称:SHATE,代码行数:18,代码来源:ExceptionMessage.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Sockets.StateObject类代码示例发布时间:2022-05-26
下一篇:
C# Sockets.SocketAsyncResult类代码示例发布时间: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