예제 #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
파일: Connection.cs 프로젝트: otbr/OTSharp
 /// <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();
 }