private static Task SendAsync(TcpClient client, CancellationToken ct, string username) { return(Task.Factory.StartNew(async() => { string firstPart = ""; while (true) { if (ManageInput(username, out firstPart)) { var inputUser = firstPart + C.Read().Trim(); if (inputUser.ToLower().Contains("file")) { try{ await SocketFileHandler.Start(client); }catch (Exception) {} } var message = username + inputUser; var b = Encoding.UTF8.GetBytes(message); C.Cursor(message.Length, Console.CursorTop - 1); //don't show Enter pressed if (client.Connected) { client.GetStream()?.WriteAsync(b, 0, b.Length); } } } }, ct)); }
private static Task ServerBroadCastAsync(string serverUsername, CancellationToken ct) { return(Task.Factory.StartNew(async() => { string firstChar; while (true) { if (ManageInput(serverUsername, out firstChar, server: true)) { var inputUser = firstChar + C.Read().Trim(); if (inputUser.ToLower().Contains("file")) { try{ await SocketFileHandler.Start(null); }catch (Exception) {} } var message = serverUsername + inputUser; C.Cursor(message.Length, Console.CursorTop - 1); //don't show Enter pressed await SocketMessageHandler.ServerSide(new TcpClient(), message, true); if (Users.Where(u => u.Client.Connected).Count() > 0) { Display.Receipt(); } } } }, ct)); }