private void EndAccept(IAsyncResult result)
#endif
        {
            Socket peerSocket = null;

            try
            {
#if NETSTANDARD1_5
                Socket listener = listenerSocket; //(Socket)result.AsyncState;
                peerSocket = result;              //listener.EndAccept(result);
#else
                Socket listener = (Socket)result.AsyncState;
                peerSocket = listener.EndAccept(result);
#endif

                IPEndPoint  endpoint   = (IPEndPoint)peerSocket.RemoteEndPoint;
                Uri         uri        = new Uri("tcp://" + endpoint.Address.ToString() + ':' + endpoint.Port);
                Peer        peer       = new Peer("", uri, EncryptionTypes.All);
                IConnection connection = null;
                if (peerSocket.AddressFamily == AddressFamily.InterNetwork)
                {
                    connection = new IPV4Connection(peerSocket, true);
                }
                else
                {
                    connection = new IPV6Connection(peerSocket, true);
                }


                RaiseConnectionReceived(peer, connection, null);
            }
            catch (SocketException)
            {
                // Just dump the connection
                if (peerSocket != null)
#if NETSTANDARD1_5
                { peerSocket.Dispose(); }
#else
                { peerSocket.Close(); }
#endif
            }
            catch (ObjectDisposedException)
            {
                // We've stopped listening
            }
            finally
            {
                try
                {
                    if (Status == ListenerStatus.Listening)
                    {
#if NETSTANDARD1_5
                        var r = await listener.AcceptAsync();

                        EndAccept(r, listener);
#else
                        listener.BeginAccept(endAcceptCallback, listener);
#endif
                    }
                }
                catch (ObjectDisposedException)
                {
                }
            }
        }