/// <summary> /// Closes the socket /// </summary> public void Close() { if (ConnectionSocket != null) { ConnectionSocket.Close(); ConnectionSocket = null; } Disconnected?.Invoke(this, EventArgs.Empty); }
// 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(); } }
public void Unbind() { //Check not already attached. if (IsBound) { ConnectionSocket.Close(); //Indicate No longer bound UnFlagBound(); } }
/// <summary> /// Closes the socket /// </summary> public void Close() { if (ConnectionSocket != null) { if (ConnectionSocket.Connected) { ConnectionSocket.Disconnect(true); } ConnectionSocket.Shutdown(SocketShutdown.Both); ConnectionSocket.Close(); } }
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(); } }
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()}"); } }
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(); } }
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()}"); } }
// 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; }
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); } }
public int Disconnect() { ConnectionStatus = 4; try { ConnectionReceive.Close(); ConnectionSend.Close(); ConnectionSocket.Close(); ConnectionStatus = 0; } catch (Exception e) { ConnectionStatus = 2; } return(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(); }
/// <summary> /// Close this connection network /// </summary> public void Disconnect() { Stream.Close(); ConnectionSocket.Close(); }
/// <summary> /// Close this connection network /// </summary> public void Disconnect() { Stream.Close(); ConnectionSocket.Close(); LoggedIn = false; }
public void Stop() { Send("</stream:stream>"); ConnectionSocket.Shutdown(SocketShutdown.Both); ConnectionSocket.Close(); }