示例#1
0
        void DropConnection()
        {
            if (Socket != null)
            {
#if NETSTANDARD_2_0 || NET_4_5 || __MOBILE__
                Socket.Disconnect(false);
#else
                Socket.Dispose();
#endif
            }
        }
示例#2
0
        //------------------------------------------------------------------------------------------------------------------------
        protected override void onClose(string Message)
        {
            try
            {
                base.onClose(Message);

                //close all
                try
                {
                    if (streamIn != null)
                    {
#if NETFX
                        TaskEx.RunSafe(streamIn.Close, AssertException: false)?.Wait(1000);
#endif
                        TaskEx.RunSafe(streamIn.Dispose, AssertException: false)?.Wait(1000);
                    }
                }
                catch { }

                try
                {
                    if (streamOut != null)
                    {
#if NETFX
                        TaskEx.RunSafe(streamOut.Close, AssertException: false)?.Wait(1000);
#endif
                        TaskEx.RunSafe(streamOut.Dispose, AssertException: false)?.Wait(1000);
                    }
                }
                catch { }

#if NETFX
                try
                {
                    if (netstream != null)
                    {
                        TaskEx.RunSafe(netstream.Close, AssertException: false)?.Wait(1000);
                        TaskEx.RunSafe(netstream.Dispose, AssertException: false)?.Wait(1000);
                    }
                }
                catch { }
#endif
                try
                {
#if NETFX
                    if (_sock?.Connected == true)
                    {
                        TaskEx.RunSafe(() => _sock?.Disconnect(false), AssertException: false)?.Wait(1000);
                    }

                    TaskEx.RunSafe(() => _sock?.Close(3), AssertException: false)?.Wait(5000);
#endif
                    TaskEx.RunSafe(() => _sock?.Dispose(), AssertException: false)?.Wait(1000);
                }
                catch { }

                //null them
                streamIn  = null;
                streamOut = null;
#if NETFX
                netstream = null;
#endif
                _sock = null;
            }
            catch (Exception ex) { DebugEx.Assert(ex, "YPC (" + Name + ") Exception while disconnecting"); }
        }