Пример #1
0
 /// <summary>
 /// Closes the socket
 /// </summary>
 public void Close()
 {
     if (ConnectionSocket != null)
     {
         ConnectionSocket.Close();
         ConnectionSocket = null;
     }
     Disconnected?.Invoke(this, EventArgs.Empty);
 }
Пример #2
0
        // Override EntityBase's definition of Dispose to Dispose base class objects, but also the Socket object
        //   that is defined in this class.
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                ConnectionSocket.Close();
                ConnectionSocket.Dispose();
            }
        }
Пример #3
0
        public void Unbind()
        {
            //Check not already attached.
            if (IsBound)
            {
                ConnectionSocket.Close();

                //Indicate No longer bound
                UnFlagBound();
            }
        }
Пример #4
0
 /// <summary>
 /// Closes the socket
 /// </summary>
 public void Close()
 {
     if (ConnectionSocket != null)
     {
         if (ConnectionSocket.Connected)
         {
             ConnectionSocket.Disconnect(true);
         }
         ConnectionSocket.Shutdown(SocketShutdown.Both);
         ConnectionSocket.Close();
     }
 }
Пример #5
0
        internal virtual void DataArrival(IAsyncResult asyncResult)
        {
            var bytesRecived = 0;

            try
            {
                // TODO: Foi Forçado o cancelamento de uma conexão pelo host remoto.
                bytesRecived = ConnectionSocket.EndReceive(asyncResult);
            }
            catch (Exception e)
            {
                var trace = new StackTrace(e, true);
                Log.Print(LogType.Error,
                          $"{e.Message}: {e.Source}" +
                          $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
            }

            if (bytesRecived != 0)
            {
                var data = new byte[bytesRecived];
                Array.Copy(DataBuffer, data, bytesRecived);

                OnPacket(data);

                try
                {
                    // TODO: Cannot access a disposed object.
                    ConnectionSocket.BeginReceive(DataBuffer, 0, DataBuffer.Length, SocketFlags.None, DataArrival,
                                                  null);
                }
                catch (SocketException e)
                {
                    var trace = new StackTrace(e, true);
                    Log.Print(LogType.Error,
                              $"{e.Message}: {e.Source}" +
                              $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
                    ConnectionSocket.Close();
                }
                catch (Exception e)
                {
                    var trace = new StackTrace(e, true);
                    Log.Print(LogType.Error,
                              $"{e.Message}: {e.Source}" +
                              $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
                }
            }
            else
            {
                Disconnect();
            }
        }
Пример #6
0
 private void Disconnect()
 {
     try
     {
         Log.Print(LogType.AuthServer, "User Disconnected");
         ConnectionSocket.Shutdown(SocketShutdown.Both);
         ConnectionSocket.Close();
     }
     catch (Exception e)
     {
         var trace = new StackTrace(e, true);
         Log.Print(LogType.Error, $"{e.Message}: {e.Source}\n{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
     }
 }
Пример #7
0
        public virtual void DataArrival(IAsyncResult asyncResult)
        {
            var bytesRecived = 0;

            try
            {
                bytesRecived = ConnectionSocket.EndReceive(asyncResult);
            }
            catch (Exception e)
            {
                var trace = new StackTrace(e, true);
                Log.Print(LogType.Error,
                          $"{e.Message}: {e.Source}" +
                          $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
            }

            if (bytesRecived != 0)
            {
                var data = new byte[bytesRecived];
                Array.Copy(DataBuffer, data, bytesRecived);

                OnPacket(data);

                try
                {
                    ConnectionSocket.BeginReceive(DataBuffer, 0, DataBuffer.Length, SocketFlags.None, DataArrival,
                                                  null);
                }
                catch (SocketException e)
                {
                    var trace = new StackTrace(e, true);
                    Log.Print(LogType.Error,
                              $"{e.Message}: {e.Source}" +
                              $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
                    ConnectionSocket.Close();
                }
                catch (Exception e)
                {
                    var trace = new StackTrace(e, true);
                    Log.Print(LogType.Error,
                              $"{e.Message}: {e.Source}" +
                              $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
                }
            }
            else
            {
                Disconnect();
            }
        }
Пример #8
0
 private void Disconnect()
 {
     try
     {
         // TODO: Cannot access a disposed object.
         ConnectionSocket.Shutdown(SocketShutdown.Both);
         ConnectionSocket.Close();
     }
     catch (Exception e)
     {
         var trace = new StackTrace(e, true);
         Log.Print(LogType.Error,
                   $"{e.Message}: {e.Source}" +
                   $"{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}");
     }
 }
Пример #9
0
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                ConnectionSocket?.Close();
            }

            // Free any unmanaged objects here.
            //
            _disposed = true;
        }
Пример #10
0
 private void CloseSocket()
 {
     try
     {
         ConnectionSocket.Close();
     }
     catch (SocketException ex)
     {
         Logger.Log(LogLevel.Error, ex.Message);
     }
     catch (ObjectDisposedException) { }
     catch (Exception ex)
     {
         throw new ConnectionException("Exception while closing socket! Exception message: " + ex.Message, ex);
     }
 }
Пример #11
0
        public int Disconnect()
        {
            ConnectionStatus = 4;

            try
            {
                ConnectionReceive.Close();
                ConnectionSend.Close();
                ConnectionSocket.Close();
                ConnectionStatus = 0;
            }
            catch (Exception e)
            {
                ConnectionStatus = 2;
            }

            return(0);
        }
Пример #12
0
        public virtual void Disconnect()
        {
            try
            {
                Log.Print(LogType.Server, "User Disconnected");

                ConnectionSocket.Close();

                //Null Check for login session.
                if (OnSessionDisconnect != null)
                {
                    OnSessionDisconnect(this);
                }
            }
            catch (Exception socketException)
            {
                Log.Print(LogType.Error, socketException.ToString());
            }
        }
        protected Result UnbindSocket()
        {
            try
            {
                if (!IsBound)
                {
                    return(Result.Success);
                }

                Result unbind;
                if (!(unbind = CloseConnections()))
                {
                    return(unbind);
                }

                ConnectionSocket.Close(NetworkConfig.CloseConnectionTimeout);
                return(unbind);
            }
            catch (Exception e)
            {
                return(Result.Error(e));
            }
        }
 public void Close()
 {
     Console.WriteLine("WebSocketConnection(): Close()!");
     ConnectionSocket.Close();
 }
Пример #15
0
 /// <summary>
 /// Close this connection network
 /// </summary>
 public void Disconnect()
 {
     Stream.Close();
     ConnectionSocket.Close();
 }
Пример #16
0
 /// <summary>
 /// Close this connection network
 /// </summary>
 public void Disconnect()
 {
     Stream.Close();
     ConnectionSocket.Close();
     LoggedIn = false;
 }
Пример #17
0
 public void Stop()
 {
     Send("</stream:stream>");
     ConnectionSocket.Shutdown(SocketShutdown.Both);
     ConnectionSocket.Close();
 }