public void Reconnect() { Console.WriteLine("Reconnecting..."); new Thread(new ThreadStart(delegate { client.Close(); Thread.Sleep(500); Connect(); })).Start(); }
public void Reconnect() { Log.Info("Reconnecting..."); new Thread(new ThreadStart(delegate { client.Close(); Thread.Sleep(500); Connect(); })).Start(); }
void ProcessMessage(ClientConnection client, Logout message) { if (client.Avatar != null) { // remove from world. _world.Remove(client.Avatar); } _log.Info("Logged out '" + client.AuthenticatedUsername + "'."); client.Close(); }
private static async Task PipeAsync(ClientConnection client, IConnection conn) { var readBytes = ConnectionExtensions.GetBytes(out var readDisposable); var writeBytes = ConnectionExtensions.GetBytes(out var writeDisposable); var readTask = Task.Run(async() => { try { for (; ;) { var result = await client.ReceiveAsync(readBytes); if (result == 0) { return;//FIN } await conn.SendAsync(readBytes.Slice(0, result)); } } finally { conn.Close(); } }); var writeTask = Task.Run(async() => { try { for (; ;) { var result = await conn.ReceiveAsync(writeBytes); if (result == 0) { return;//FIN } await client.SendAsync(writeBytes.Slice(0, result)); } } finally { client.Close(); } }); try { await Task.WhenAll(readTask, writeTask); } finally { readDisposable.Dispose(); writeDisposable.Dispose(); } }
void ProcessMessage(ClientConnection client, Login loginMessage) { if (_world.UserLookup(loginMessage.Username, loginMessage.Password, ref client.PlayerId)) { // login succeeded, check there is not an existing connection for this player foreach (ClientConnection c in _listener.Clients .Where(c => c != client && c.AuthenticatedUsername == loginMessage.Username)) { c.Close(); } _log.Info("User " + loginMessage.Username + " logged in"); client.AuthenticatedUsername = loginMessage.Username; } else { _log.Info("Login failed for username '" + loginMessage.Username + "'"); client.Close(); } }
void IConnectionsService.Remove(ClientConnection connection) { connections.Remove(connection); connection.UserObject.Status = Status.Offline; try { using (var context = new DataBaseContext()) { var user = context.Users.FirstOrDefault(u => u.AccessToken == connection.UserObject.AccessToken); user.Status = Status.Offline; context.SaveChanges(); } } catch (Exception exception) { logger.Write(exception); } connection.Close(); }
public void DisconnectFromServer() { if (!Connection.Connected) { return; } _updateTimer.Stop(); SoundEngine.StopAllChannels(); Connection.Close(); Interface = null; SoundEngine = null; ResourceManager = null; StateManager = null; Map = null; ATOMs = null; ScreenObjects = null; IconAppearances = null; MainWindow.Show(); }
public void Close() { // Something called close twice, so let's just wait for the other thread to finish. if (exited) { exitEvent.WaitOne(); } // Initialize close sequence else { exited = true; //if (ReadThread != null && WriteThread != null) //{ // if (ReadThread.IsAlive || WriteThread.IsAlive) // { // ReadThread.Join(); // WriteThread.Join(); // } //} // Kill the socket. if (ClientConnection != null) { try { ClientConnection.Close(); } catch (Exception ex) { //DebugWriteLine($"Error closing socket to {IPAddress}: {ex.Message}"); } } // Remove everything. OnDisconnect(this.ServerID); // Notify other callers you can terminate. exitEvent.Set(); } }
public void WhenICloseTheClientConnection() { ClientConnection.Close(); }
public void CloseTCPConnection() { clientConnection.Close(); }
private void Close() { ConnectionStream.Dispose(); ClientConnection.Close(); Server.Stop(); }
public void Close() { ClientConnection.Close(); ConnectionStream.Dispose(); }