private void OnConnectionStatusChanged(Connection conn, ConnectionInfo info) { ulong clientSteamID = info.Identity.SteamId; if (info.State == ConnectionState.Connected) { Connected = true; OnConnected.Invoke(); Debug.Log("Connection established."); if (BufferedData.Count > 0) { Debug.Log($"{BufferedData.Count} received before connection was established. Processing now."); { foreach (Action a in BufferedData) { a(); } } } } else if (info.State == ConnectionState.ClosedByPeer) { Connected = false; OnDisconnected.Invoke(); Debug.Log("Disconnected."); conn.Close(false, 0, "Disconnected"); } else { Debug.Log($"Connection state changed: {info.State.ToString()}"); } }
protected override void OnReceiveInternalData(InternalMessages type, CSteamID clientSteamID) { switch (type) { case InternalMessages.ACCEPT_CONNECT: if (!Connected) { Connected = true; OnConnected.Invoke(); Debug.Log("Connection established."); } break; case InternalMessages.DISCONNECT: if (Connected) { Connected = false; Debug.Log("Disconnected."); OnDisconnected.Invoke(); } break; default: Debug.Log("Received unknown message type"); break; } }
protected override void OnReceiveInternalData(InternalMessages type, ProductUserId clientUserId) { switch (type) { case InternalMessages.CONNECT: if (epicToMirrorIds.Count >= maxConnections) { SendInternal(clientUserId, InternalMessages.DISCONNECT); return; } SendInternal(clientUserId, InternalMessages.ACCEPT_CONNECT); int connectionId = nextConnectionID++; epicToMirrorIds.Add(clientUserId, connectionId); OnConnected.Invoke(connectionId); Debug.Log($"Client with Product User ID {clientUserId} connected. Assigning connection id {connectionId}"); break; case InternalMessages.DISCONNECT: if (epicToMirrorIds.TryGetValue(clientUserId, out int connId)) { OnDisconnected.Invoke(connId); CloseP2PSessionWithUser(clientUserId); epicToMirrorIds.Remove(clientUserId); Debug.Log($"Client with Product User ID {clientUserId} disconnected."); } else { OnReceivedError.Invoke(-1, new Exception("ERROR Unknown Product User ID")); } break; default: Debug.Log("Received unknown message type"); break; } }
public void Disconnect() { try { if (Reader != null) { Reader.Abort(); } if (Connection != null) { Connection.Close(); } } catch (Exception ex) { Trace.WriteLine("IRC/Server/Disconnect: " + ex); } finally { Connection = null; Event.Invoke(this, Event.ServerEventType.Disconnected, null); if (OnDisconnected != null) { OnDisconnected.Invoke(this); } } }
private void OnConnDisconnected(object sender, FizzMqttDisconnectedArgs args) { FizzLogger.D("MQTT - OnDisconnected: " + args.ClientWasConnected.ToString()); if (OnDisconnected != null) { if (args.Exception == null) { OnDisconnected.Invoke(null); } else { if (args.Exception.GetType() == typeof(FizzMqttAuthException)) { OnDisconnected.Invoke(ERROR_AUTH_FAILED); if (_sessionRepo != null) { _sessionRepo.FetchToken(null); } } else { OnDisconnected.Invoke(ERROR_CONNECTION_FAILED); } } } if (_closeCallback != null) { FizzUtils.DoCallback(_closeCallback); } }
public bool Disconnect() { if (Connected) { try { //Disconnect the TcpClient client.Close(); } catch (Exception ex) { Logger.Error("Failed to disconnect : " + ex.Message, DebugLevel); return(false); } } //Invoke the event if (OnDisconnected != null) { OnDisconnected.Invoke(); } return(true); }
private void OnConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t param) { ulong clientSteamID = param.m_info.m_identityRemote.GetSteamID64(); if (param.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connected) { Connected = true; OnConnected.Invoke(); Debug.Log("Connection established."); if (BufferedData.Count > 0) { Debug.Log($"{BufferedData.Count} received before connection was established. Processing now."); { foreach (Action a in BufferedData) { a(); } } } } else if (param.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer) { Connected = false; OnDisconnected.Invoke(); Debug.Log("Disconnected."); SteamNetworkingSockets.CloseConnection(param.m_hConn, 0, "Disconnected", false); } else { Debug.Log($"Connection state changed: {param.m_info.m_eState.ToString()}"); } }
/// <summary> /// Listens to incoming messages, and starts async receivers (blocking call) /// </summary> private void ReceiveAsync() { using (var receiveDone = new ManualResetEvent(false)) { while (IsConnected) { _ = receiveDone.Reset(); var state = new StateObject { length = 2, bytes = new byte[2], signal = receiveDone }; try { _ = _socket.BeginReceive(state.bytes, 0, state.length, 0, MessageLengthReceivedCallback, state); } catch (Exception ex) { System.Console.WriteLine("Exception caught: {0}", ex.Message); } _ = receiveDone.WaitOne(); } } OnDisconnected.Invoke(this); }
private void OnConnDisconnected(int connId, object sender, MqttClientDisconnectedEventArgs args) { if (_connection != null && _connection.Id != connId) { FizzLogger.W("Received disconnected event for old connection."); } FizzLogger.D("MQTT - OnDisconnected: " + args.ClientWasConnected.ToString()); if (OnDisconnected != null) { if (args.Exception == null) { OnDisconnected.Invoke(null); } else { if (args.Exception.GetType() == typeof(MQTTnet.Adapter.MqttConnectingFailedException)) { OnDisconnected.Invoke(ERROR_AUTH_FAILED); if (_sessionRepo != null) { _sessionRepo.FetchToken(null); } } else { OnDisconnected.Invoke(ERROR_CONNECTION_FAILED); } } } }
protected override void OnReceiveInternalData(InternalMessages type, ProductUserId clientUserId, SocketId socketId) { if (ignoreAllMessages) { return; } switch (type) { case InternalMessages.ACCEPT_CONNECT: Connected = true; OnConnected.Invoke(); Debug.Log("Connection established."); break; case InternalMessages.DISCONNECT: Connected = false; Debug.Log("Disconnected."); OnDisconnected.Invoke(); break; default: Debug.Log("Received unknown message type"); break; } }
void Listener_OnDisconnected(FizzException obj) { if (OnDisconnected != null) { OnDisconnected.Invoke(obj); } }
protected override void OnReceiveInternalData(InternalMessages type, CSteamID clientSteamID) { switch (type) { case InternalMessages.CONNECT: if (steamToMirrorIds.Count >= maxConnections) { SendInternal(clientSteamID, InternalMessages.DISCONNECT); return; } SendInternal(clientSteamID, InternalMessages.ACCEPT_CONNECT); int connectionId = nextConnectionID++; steamToMirrorIds.Add(clientSteamID, connectionId); OnConnected.Invoke(connectionId); Debug.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}"); break; case InternalMessages.DISCONNECT: if (steamToMirrorIds.TryGetValue(clientSteamID, out int connId)) { OnDisconnected.Invoke(connId); CloseP2PSessionWithUser(clientSteamID); steamToMirrorIds.Remove(clientSteamID); Debug.Log($"Client with SteamID {clientSteamID} disconnected."); } break; default: Debug.Log("Received unknown message type"); break; } }
private void InternalDisconnect() { Connected = false; OnDisconnected.Invoke(); Debug.Log("Disconnected."); SteamNetworkingSockets.CloseConnection(HostConnection, 0, "Disconnected", false); }
public void Disconnect() { lock (_lock) { try { _state.Size = CmppConstants.HeaderSize; _state.PackageType = typeof(CmppHead); _state.Header = null; lock (_receiveQueue) _receiveQueue.Clear(); if (_socket == null) { return; } _socket.Disconnect(false); _socket.Dispose(); } finally { _socket = null; if (OnDisconnected != null) { OnDisconnected.Invoke(this, null); } } } }
private void InternalDisconnect(int connId, HSteamNetConnection socket) { OnDisconnected.Invoke(connId); SteamNetworkingSockets.CloseConnection(socket, 0, "Graceful disconnect", false); connToMirrorID.Remove(connId); steamIDToMirrorID.Remove(connId); Debug.Log($"Client with ConnectionID {connId} disconnected."); }
protected override void OnConnectionFailed(CSteamID remoteId) { int connectionId = steamToMirrorIds.TryGetValue(remoteId, out int connId) ? connId : nextConnectionID++; OnDisconnected.Invoke(connectionId); steamToMirrorIds.Remove(remoteId); }
private void InternalDisconnect(int connId, Connection socket) { OnDisconnected.Invoke(connId); socket.Close(false, 0, "Graceful disconnect"); connToMirrorID.Remove(connId); steamIDToMirrorID.Remove(connId); Debug.Log($"Client with SteamID {connId} disconnected."); }
protected override void OnConnectionFailed(ProductUserId remoteId) { int connectionId = epicToMirrorIds.TryGetValue(remoteId, out int connId) ? connId : nextConnectionID++; OnDisconnected.Invoke(connectionId); epicToMirrorIds.Remove(remoteId); }
private void Run() { while (alive) { try { lock (clientList) { int index = 0; while (index < clientList.Count) { if (!IsConnected(clientList[index])) { if (OnDisconnected != null) { OnDisconnected.Invoke(clientList[index].Client.LocalEndPoint, clientList[index].Client.RemoteEndPoint); } clientList.RemoveAt(index); } else { index++; } } foreach (TcpClient client in clientList) { NetworkStream stream = client.GetStream(); if (stream != null) { byte[][] commands = ReceiveBytes(stream); if (OnReceived != null) { foreach (byte[] command in commands) { byte[] response = OnReceived.Invoke(command); if (response != null && response.Length > 0) { SendBytes(stream, response, terminator); } } } } } } } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #endif } finally { Thread.Sleep(interval); } } }
private void OnClosedConnection(object sender, ConnectionEventArgs e) { connectionsByName.Remove(e.Connection.Name); UpdateConnections(); if (OnDisconnected != null) { OnDisconnected.Invoke(this, e); } }
/// <summary> /// Called by connection when it is disconnected /// </summary> internal void OnConnectionDisconnected(Connection connection, DisconnectReason reason, bool sendToOther) { if (sendToOther) { SendCommand(connection, Commands.Disconnect, (byte)reason); } // tell high level OnDisconnected.Invoke(connection, reason); }
protected override void OnReceiveInternalData(InternalMessages type, ProductUserId clientUserId, SocketId socketId) { if (ignoreAllMessages) { return; } switch (type) { case InternalMessages.CONNECT: if (epicToMirrorIds.Count >= maxConnections) { Debug.LogError("Reached max connections"); //CloseP2PSessionWithUser(clientUserId, socketId); SendInternal(clientUserId, socketId, InternalMessages.DISCONNECT); return; } SendInternal(clientUserId, socketId, InternalMessages.ACCEPT_CONNECT); int connectionId = nextConnectionID++; epicToMirrorIds.Add(clientUserId, connectionId); epicToSocketIds.Add(clientUserId, socketId); Debug.LogError("Adding new connection with ID: " + connectionId); OnConnected.Invoke(connectionId); string clientUserIdString; clientUserId.ToString(out clientUserIdString); Debug.Log($"Client with Product User ID {clientUserIdString} connected. Assigning connection id {connectionId}"); break; case InternalMessages.DISCONNECT: if (epicToMirrorIds.TryGetValue(clientUserId, out int connId)) { OnDisconnected.Invoke(connId); //CloseP2PSessionWithUser(clientUserId, socketId); epicToMirrorIds.Remove(clientUserId); epicToSocketIds.Remove(clientUserId); Debug.LogError($"Client with Product User ID {clientUserId} disconnected."); } else { OnReceivedError.Invoke(-1, new Exception("ERROR Unknown Product User ID")); } break; default: Debug.Log("Received unknown message type"); break; } }
/// <summary> /// Removes session and account from cache, logs out of Facebook and invokes <see cref="OnDisconnected"/>. /// </summary> public void Disconnect() { if (Session == null) { return; } else { Session = null; Account = null; Debug.Log("Disconnected from Nakama"); OnDisconnected.Invoke(); } }
protected override void OnConnectionFailed(ProductUserId remoteId) { if (ignoreAllMessages) { return; } int connectionId = epicToMirrorIds.TryGetValue(remoteId, out int connId) ? connId : nextConnectionID++; OnDisconnected.Invoke(connectionId); Debug.LogError("Connection Failed, removing user"); epicToMirrorIds.Remove(remoteId); epicToSocketIds.Remove(remoteId); }
private void OnConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t param) { ulong clientSteamID = param.m_info.m_identityRemote.GetSteamID64(); if (param.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connecting) { if (connToMirrorID.Count >= maxConnections) { Debug.Log($"Incoming connection {clientSteamID} would exceed max connection count. Rejecting."); SteamNetworkingSockets.CloseConnection(param.m_hConn, 0, "Max Connection Count", false); return; } EResult res; if ((res = SteamNetworkingSockets.AcceptConnection(param.m_hConn)) == EResult.k_EResultOK) { Debug.Log($"Accepting connection {clientSteamID}"); } else { Debug.Log($"Connection {clientSteamID} could not be accepted: {res.ToString()}"); } } else if (param.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_Connected) { int connectionId = nextConnectionID++; connToMirrorID.Add(param.m_hConn, connectionId); steamIDToMirrorID.Add(param.m_info.m_identityRemote.GetSteamID(), connectionId); OnConnected.Invoke(connectionId); Debug.Log($"Client with SteamID {clientSteamID} connected. Assigning connection id {connectionId}"); } else if (param.m_info.m_eState == ESteamNetworkingConnectionState.k_ESteamNetworkingConnectionState_ClosedByPeer) { if (connToMirrorID.TryGetValue(param.m_hConn, out int connId)) { OnDisconnected.Invoke(connId); SteamNetworkingSockets.CloseConnection(param.m_hConn, 0, "Graceful disconnect", false); connToMirrorID.Remove(connId); steamIDToMirrorID.Remove(connId); Debug.Log($"Client with SteamID {clientSteamID} disconnected."); } } else { Debug.Log($"Connection {clientSteamID} state changed: {param.m_info.m_eState.ToString()}"); } }
/// <summary> /// Disconnects from the remote server. /// </summary> /// <param name="silent">If true then no event will be trigered (used in redirect process)</param> public void Disconnect(bool silent = false) { if (Connected()) { apiReadStream.Close(); apiWriteStream.Close(); apiSocket.Close(); if (!silent && OnDisconnected != null) { OnDisconnected.Invoke(); } } apiConnected = false; }
void IClientTransportLayer.Update() { while (_client.GetNextMessage(out var msg)) { switch (msg.eventType) { case Telepathy.EventType.Connected: _clientConnectedCallback.Invoke(_channelId); break; case Telepathy.EventType.Data: _clientMessageCallback.Invoke(msg.data); break; case Telepathy.EventType.Disconnected: _clientDisconnectedCallback.Invoke(_channelId); break; } } }
/// <summary> /// Отключиться от конечной точки /// </summary> public void Disconnect() { bool disconnect; lock (connectionsToDisconnectAwait) disconnect = connectionsToDisconnectAwait.Remove(this); if (disconnect) { if (Opitions.EventOriented && OnDisconnected != null) { OnDisconnected.Invoke(this); } } if (connection != null && connection.Connected) { connection.Close(); } }
/// <summary> /// Close connection. /// </summary> /// <param name="isInitiative"> /// If true, will send a Close command to the client side. Like saying "Hey, I'm closing the connection! (Do something if you need.)" /// If false, just close without telling the client. False can be used when has been told to close(client sent the Close command to here) and no need to notify back. /// </param> public void Close(bool isInitiative = false) { doReceive = false; if (socket != null) { if (socket.Connected) { if (isInitiative) { SendType(DataType.Close); } Thread.Sleep(30); socket.Shutdown(SocketShutdown.Both); socket.Close(); } if (OnDisconnected != null) { OnDisconnected.Invoke(this, new ConnectionEventArgs(this)); } } }
/// <summary> /// Removes session and account from cache, logs out of Facebook and invokes <see cref="OnDisconnected"/>. /// </summary> public void Disconnect() { if (FB.IsLoggedIn == true) { FB.LogOut(); Debug.Log("Disconnected from Facebook"); } if (Session == null) { return; } else { Session = null; Account = null; Debug.Log("Disconnected from Nakama"); OnDisconnected.Invoke(); } }