//public static void Send(string str) //{ // if (!connection.Connected) Connect(); // connection.Send(Encoding.ASCII.GetBytes(str + "\0")); //} //public static void SendAndDisconnect(string str) //{ // if (connection.Connected) // { // connection.Send(Encoding.ASCII.GetBytes(str)); // } // Disconnect(str); //} //public static void Disconnect(string str="You Disconnected!") //{ // timer.Stop(); // if (connection.Connected) // { // connection.Close(); // MessageBox.Show(str, "Disconnect", MessageBoxButtons.OK); // } // status = Status.Disconnect; // ChangeStatus(status.ToString()); // //need add go to login Form //} private static void Disconnect(Block block) { CloseConnection(); DisconnectType state = (DisconnectType)block.Type; switch (state) { case DisconnectType.Exit: MessageBox.Show("Exit!", state.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information); break; case DisconnectType.Error: MessageBox.Show("Wrong Command!", state.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); break; case DisconnectType.Timeout: MessageBox.Show("Timeout!", state.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show("Command Error!", state.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); break; } }
/// <summary> /// 停止收发并关闭socket /// </summary> public void Close(DisconnectType e = DisconnectType.Manual) { lock (lockobj) { if (isRuning == true) { isRuning = false; try { socket.Shutdown(SocketShutdown.Send); } catch (Exception) { } try { socket.Shutdown(SocketShutdown.Receive); } catch (Exception) { } socket.Close(); if (socketPool != null) { if (readArgs != null) { readArgs.Completed -= readArgs_Completed; socketPool.Push(readArgs); readArgs.UserToken = null; } } socket = null; OnSocketDisconnecting(new DisconnectEvent(e, this)); } IsConnect = false; } }
public void TriggerPeerDisconnected(DisconnectReason reason, DisconnectType disconnectType) { PeerDisconnected?.Invoke(this, new DisconnectEventArgs(reason, disconnectType)); var task = Task.Delay(1000); task.Wait(); }
public static void DisconnectHandler(DisconnectType type, string message) { if (type == DisconnectType.NetworkTimeout) { Console.WriteLine("Network connection timed out, disconnected"); } else if (type == DisconnectType.ServerInitiated) { Console.WriteLine("Server disconnected us: " + message); } }
public static void DisconnectHandler(DisconnectType type, string message) { if (type == DisconnectType.NetworkTimeout) { Console.WriteLine("Network connection timed out, disconnected"); } else if (type == DisconnectType.ServerInitiated) { Console.WriteLine("Server disconnected us: " + message); } }
void Disconnected(DisconnectType dis, string msg) { Close(); string protocal = dis == DisconnectType.System ? SocketStatusCMD.Exception : SocketStatusCMD.Disconnect; NetByteBuffer buffer = new NetByteBuffer(); buffer.WriteString(protocal); SocketClientManager.AddEvent(protocal, buffer); DebugConsole.LogError("Disconnected :>" + msg + " DisconnectType:>" + dis); }
/// <summary> /// Shutdown will disconnect all the sims except for the current sim /// first, and then kill the connection to CurrentSim. This should only /// be called if the logout process times out on <code>RequestLogout</code> /// </summary> public void Shutdown(DisconnectType type) { Client.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info); // Send a CloseCircuit packet to simulators if we are initiating the disconnect bool sendCloseCircuit = (type == DisconnectType.ClientInitiated || type == DisconnectType.NetworkTimeout); lock (Simulators) { // Disconnect all simulators except the current one for (int i = 0; i < Simulators.Count; i++) { if (Simulators[i] != null && Simulators[i] != CurrentSim) { Simulators[i].Disconnect(sendCloseCircuit); // Fire the SimDisconnected event if a handler is registered if (OnSimDisconnected != null) { try { OnSimDisconnected(Simulators[i], type); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } } Simulators.Clear(); } if (CurrentSim != null) { // Kill the connection to the curent simulator CurrentSim.Disconnect(sendCloseCircuit); // Fire the SimDisconnected event if a handler is registered if (OnSimDisconnected != null) { try { OnSimDisconnected(CurrentSim, type); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } // Clear out all of the packets that never had time to process PacketInbox.Close(); connected = false; // Fire the disconnected callback if (OnDisconnected != null) { try { OnDisconnected(DisconnectType.ClientInitiated, String.Empty); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
public void AddNodeStatsDisconnectEvent(DisconnectType disconnectType, DisconnectReason disconnectReason) { _lastDisconnectTime = DateTime.UtcNow; if (disconnectType == DisconnectType.Local) { _lastLocalDisconnect = disconnectReason; } else { _lastRemoteDisconnect = disconnectReason; } Increment(NodeStatsEventType.Disconnect); }
void OnDisconnect(DisconnectType dis, string msg) { if (dis != DisconnectType.ClientClosing) { CloseClient(); } /*ushort protocal = dis == DisconnectType.Exception ? Protocal.Exception : Protocal.Disconnect; * * ByteBuffer buffer = new ByteBuffer(); * buffer.WriteShort((ushort)protocal); * NetworkManager.PushPacket(protocal, buffer);*/ Debug.Log("Connection closed. Distype: " + dis + ". Msg: " + msg); }
void Close(Exception ex, DisconnectType dt) { if (IsClosed) { return; } IsClosed = true; TerminateThreads(); notifyDisonnect(new NodeDisconnectInfo() { node = this, exception = ex, disconnectType = dt }); }
internal void DisconnectClient(Connection connection, DisconnectType disconnectType, byte[] packet) { if (!connection.UpdateState(Connection.ConnectionState.DISCONNECTED)) { return; } if (disconnectType == DisconnectType.TIMEOUT) { Interlocked.Increment(ref Stats.StatTimeouts); if (this.OnTimeout != null) { this.OnTimeout(connection, null); } } Interlocked.Increment(ref Stats.StatDisconnects); // send more than necessary so that the packet hopefully arrives for (int i = 0; i < 10; i++) { connection.SendHighLevelPacket(Packet.PacketDescriptor.DISCONNECT, packet); } // give the channel some time to process the packets Thread.Sleep(20); connection.StopRoutines(); if (disconnectType != DisconnectType.SHUTDOWN) { uint hash = Util.AddrHash(connection.Addr); this.connectionsMutex.EnterWriteLock(); this.connections.Remove(hash); this.connectionsMutex.ExitWriteLock(); if (this.OnDisconnect != null) { this.OnDisconnect(connection, packet); } } connection.Reset(); this.connectionPool.Put(connection); }
/// <summary> /// Shutdown will disconnect all the sims except for the current sim /// first, and then kill the connection to CurrentSim. This should only /// be called if the logout process times out on <code>RequestLogout</code> /// </summary> /// <param name="type">Type of shutdown</param> public void Shutdown(DisconnectType type) { Shutdown(type, type.ToString()); }
public void Close(DisconnectType Reason) { Send(new DisconnectMessage(Reason)); Dispose(); }
/// <summary> /// Executes when some of current <see cref="MsSqlDataProvider"/> <see cref="MsSqlDataConnection"/> objects disconnects from database engine. /// </summary> /// <param name="connectionID">Disconnected <see cref="MsSqlDataConnection"/> unique id.</param> /// <param name="type">Disconnection type.</param> internal override void ConnectionDisconnected( byte connectionID, DisconnectType type ) { if ( m_ActiveConnections.Contains(connectionID) ) { Logger.WriteLine(Source.DataProvider, "Connection {0} was disconnected {1}.", connectionID, type); m_ActiveConnections.Remove(connectionID); if ( m_ActiveConnections.Count == 0 ) { Initialized = false; if ( OnStopped != null ) OnStopped(); } } }
public static void Update(DisconnectType disconnectType, DisconnectReason disconnectReason) { if (disconnectType == DisconnectType.Remote) { switch (disconnectReason) { case DisconnectReason.BreachOfProtocol: Metrics.BreachOfProtocolDisconnects++; break; case DisconnectReason.UselessPeer: Metrics.UselessPeerDisconnects++; break; case DisconnectReason.TooManyPeers: Metrics.TooManyPeersDisconnects++; break; case DisconnectReason.AlreadyConnected: Metrics.AlreadyConnectedDisconnects++; break; case DisconnectReason.IncompatibleP2PVersion: Metrics.IncompatibleP2PDisconnects++; break; case DisconnectReason.NullNodeIdentityReceived: Metrics.NullNodeIdentityDisconnects++; break; case DisconnectReason.ClientQuitting: Metrics.ClientQuittingDisconnects++; break; case DisconnectReason.UnexpectedIdentity: Metrics.UnexpectedIdentityDisconnects++; break; case DisconnectReason.ReceiveMessageTimeout: Metrics.ReceiveMessageTimeoutDisconnects++; break; case DisconnectReason.DisconnectRequested: Metrics.DisconnectRequestedDisconnects++; break; case DisconnectReason.IdentitySameAsSelf: Metrics.SameAsSelfDisconnects++; break; case DisconnectReason.TcpSubSystemError: Metrics.TcpSubsystemErrorDisconnects++; break; default: Metrics.OtherDisconnects++; break; } } if (disconnectType == DisconnectType.Local) { switch (disconnectReason) { case DisconnectReason.BreachOfProtocol: Metrics.LocalBreachOfProtocolDisconnects++; break; case DisconnectReason.UselessPeer: Metrics.LocalUselessPeerDisconnects++; break; case DisconnectReason.TooManyPeers: Metrics.LocalTooManyPeersDisconnects++; break; case DisconnectReason.AlreadyConnected: Metrics.LocalAlreadyConnectedDisconnects++; break; case DisconnectReason.IncompatibleP2PVersion: Metrics.LocalIncompatibleP2PDisconnects++; break; case DisconnectReason.NullNodeIdentityReceived: Metrics.LocalNullNodeIdentityDisconnects++; break; case DisconnectReason.ClientQuitting: Metrics.LocalClientQuittingDisconnects++; break; case DisconnectReason.UnexpectedIdentity: Metrics.LocalUnexpectedIdentityDisconnects++; break; case DisconnectReason.ReceiveMessageTimeout: Metrics.LocalReceiveMessageTimeoutDisconnects++; break; case DisconnectReason.DisconnectRequested: Metrics.LocalDisconnectRequestedDisconnects++; break; case DisconnectReason.IdentitySameAsSelf: Metrics.LocalSameAsSelfDisconnects++; break; case DisconnectReason.TcpSubSystemError: Metrics.LocalTcpSubsystemErrorDisconnects++; break; default: Metrics.LocalOtherDisconnects++; break; } } }
public override void Deserialise(Reader Reader) { Reason = (DisconnectType)Reader.ReadByte(); }
/// <summary> /// Executes when some of current <see cref="Provider"/> <see cref="Connection"/> objects disconnects from database engine. /// </summary> /// <param name="connectionID">Disconnected <see cref="Connection"/> unique id.</param> /// <param name="type">Disconnection type.</param> internal virtual void ConnectionDisconnected(byte connectionID, DisconnectType type) { Logger.WriteLine(Source.DataProvider, "Connection {0} disconnected {1}", connectionID, type); }
public DisconnectedEventArgs(DisconnectType pDCType) { Reason = pDCType; }
public DisconnectPacket(string message, DisconnectType type) { this.type = PacketType.DISCONNECT; this.disconnectType = type; this.message = message; }
public DisconnectEvent(DisconnectType dt, YChannel channel) { this.DisconnectType = dt; this.Channel = channel; }
public DisconnectCategory(DisconnectReason reason, DisconnectType type) { Reason = reason; Type = type; }
public DisconnectMessage(DisconnectType Reason) { this.Reason = Reason; }
public DisconnectEventArgs(DisconnectReason disconnectReason, DisconnectType disconnectType, string details) { DisconnectReason = disconnectReason; DisconnectType = disconnectType; Details = details; }
internal ClientDisconnectedEventArgs(TCPClientInfo clientInfo, DisconnectType disconnectType) { ClientInfo = clientInfo; DisconnectType = disconnectType; }
public DisconnectEventArgs(DisconnectReason disconnectReason, DisconnectType disconnectType) { DisconnectReason = disconnectReason; DisconnectType = disconnectType; }
public Task DisconnectAsync(DisconnectReason disconnectReason, DisconnectType disconnectType) { return(Task.CompletedTask); }
/// <summary> /// Executes when some of current <see cref="Provider"/> <see cref="Connection"/> objects disconnects from database engine. /// </summary> /// <param name="connectionID">Disconnected <see cref="Connection"/> unique id.</param> /// <param name="type">Disconnection type.</param> internal virtual void ConnectionDisconnected( byte connectionID, DisconnectType type ) { Logger.WriteLine(Source.DataProvider, "Connection {0} disconnected {1}", connectionID, type); }
public void ReportDisconnect(Node node, DisconnectType disconnectType, DisconnectReason disconnectReason) { INodeStats stats = GetOrAdd(node); stats.AddNodeStatsDisconnectEvent(disconnectType, disconnectReason); }
public DisconnectEventArgs(DisconnectReason disconnectReason, DisconnectType disconnectType, string sessionId) { DisconnectReason = disconnectReason; DisconnectType = disconnectType; SessionId = sessionId; }
internal ClientDisconnectedPacket(byte sender, byte disconnectedClientID, DisconnectType disconnectType) { Sender = sender; DisconnectedClientID = disconnectedClientID; DisconnectType = disconnectType; }
/// <summary> /// Shutdown will disconnect all the sims except for the current sim /// first, and then kill the connection to CurrentSim. This should only /// be called if the logout process times out on <code>RequestLogout</code> /// </summary> public void Shutdown(DisconnectType type) { Client.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info); // Send a CloseCircuit packet to simulators if we are initiating the disconnect bool sendCloseCircuit = (type == DisconnectType.ClientInitiated || type == DisconnectType.NetworkTimeout); lock (Simulators) { // Disconnect all simulators except the current one for (int i = 0; i < Simulators.Count; i++) { if (Simulators[i] != null && Simulators[i] != CurrentSim) { Simulators[i].Disconnect(sendCloseCircuit); // Fire the SimDisconnected event if a handler is registered if (OnSimDisconnected != null) { try { OnSimDisconnected(Simulators[i], type); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } } Simulators.Clear(); } if (CurrentSim != null) { // Kill the connection to the curent simulator CurrentSim.Disconnect(sendCloseCircuit); // Fire the SimDisconnected event if a handler is registered if (OnSimDisconnected != null) { try { OnSimDisconnected(CurrentSim, type); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } // Clear out all of the packets that never had time to process lock (PacketInbox) PacketInbox.Clear(); connected = false; // Fire the disconnected callback if (OnDisconnected != null) { try { OnDisconnected(DisconnectType.ClientInitiated, String.Empty); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
/// <summary> /// Shutdown will disconnect all the sims except for the current sim /// first, and then kill the connection to CurrentSim. This should only /// be called if the logout process times out on <code>RequestLogout</code> /// </summary> /// <param name="type">Type of shutdown</param> /// <param name="message">Shutdown message</param> public void Shutdown(DisconnectType type, string message) { Logger.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info, Client); // Send a CloseCircuit packet to simulators if we are initiating the disconnect bool sendCloseCircuit = (type == DisconnectType.ClientInitiated || type == DisconnectType.NetworkTimeout); lock (Simulators) { // Disconnect all simulators except the current one for (int i = 0; i < Simulators.Count; i++) { if (Simulators[i] != null && Simulators[i] != CurrentSim) { Simulators[i].Disconnect(sendCloseCircuit); // Fire the SimDisconnected event if a handler is registered if (m_SimDisconnected != null) { OnSimDisconnected(new SimDisconnectedEventArgs(Simulators[i], type)); } } } Simulators.Clear(); } if (CurrentSim != null) { // Kill the connection to the curent simulator CurrentSim.Disconnect(sendCloseCircuit); // Fire the SimDisconnected event if a handler is registered if (m_SimDisconnected != null) { OnSimDisconnected(new SimDisconnectedEventArgs(CurrentSim, type)); } } // Clear out all of the packets that never had time to process PacketInbox.Close(); PacketOutbox.Close(); connected = false; // Fire the disconnected callback if (m_Disconnected != null) { OnDisconnected(new DisconnectedEventArgs(type, message)); } }
public override void Deserialise(Reader Reader) { Reason = (DisconnectType)Reader.ReadByte(); }
public DisconnectedEventArgs(DisconnectType disconnectReason) { DisconnectReason = disconnectReason; }
void Disconnected(DisconnectType dis, string msg) { Close(); string protocal = dis == DisconnectType.System ? SocketStatusCMD.Exception : SocketStatusCMD.Disconnect; NetBuffer buffer = new NetBuffer(); buffer.WriteString(protocal); SocketClientManager.AddEvent(protocal, buffer); DebugConsole.LogError("Disconnected :>" + msg + " DisconnectType:>" + dis); }
public void Close(DisconnectType Reason) { Send(new DisconnectMessage(Reason)); Dispose(); }
public void TriggerPeerDisconnected(DisconnectReason reason, DisconnectType disconnectType) { PeerDisconnected?.Invoke(this, new DisconnectEventArgs(reason, disconnectType)); }
public void ReportDisconnect(DisconnectReason reason, DisconnectType type, string details) { }
/// <summary> /// Shutdown will disconnect all the sims except for the current sim /// first, and then kill the connection to CurrentSim. /// </summary> private void Shutdown(DisconnectType type) { Client.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info); lock (Simulators) { // Disconnect all simulators except the current one for (int i = 0; i < Simulators.Count; i++) { if (Simulators[i] != null && Simulators[i] != CurrentSim) { Simulators[i].Disconnect(); // Fire the SimDisconnected event if a handler is registered // FIXME: This is a recipe for disaster, locking Simulators and // firing a callback if (OnSimDisconnected != null) { try { OnSimDisconnected(Simulators[i], type); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } } Simulators.Clear(); } if (CurrentSim != null) { // Kill the connection to the curent simulator CurrentSim.Disconnect(); // Fire the SimDisconnected event if a handler is registered if (OnSimDisconnected != null) { try { OnSimDisconnected(CurrentSim, type); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } // Destroy the CurrentSim object lock (Simulators) CurrentSim = null; } // Clear out all of the packets that never had time to process lock (PacketInbox) PacketInbox.Clear(); connected = false; }
public void OnDisconnect(DisconnectType disconnectType) => Disconnect();
public DisconnectMessage(DisconnectType Reason) { this.Reason = Reason; }