public void AñadirHecho(Lista lista, DateTime fechaHecho) { listasTareaHecha.AddOrReplace(lista, fechaHecho); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Int32 port; IPAddress localAddr; TcpClient client; Byte[] bytes; NetworkStream stream; byte[] msg; Data data; TcpListener server = default; try { // Set the TcpListener on port 13000. port = 13000; localAddr = IPAddress.Parse("127.0.0.1"); // TcpListener server = new TcpListener(port); server = new TcpListener(localAddr, port); // Start listening for client requests. server.Start(); // Buffer for reading data bytes = new byte[1024]; data = default; // Enter the listening loop. while (!stoppingToken.IsCancellationRequested) { Console.Write("Waiting for a connection... "); // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. client = await server.AcceptTcpClientAsync(); Console.WriteLine("Connected!"); data = default; // Get a stream object for reading and writing stream = client.GetStream(); data = Data.GetData(stream.GetBytes()); if (data.IsAKey) { DicKeys.AddOrReplace(data.Id, data.Key); msg = MsgKeyInstalledSuccessfully; } else if (DicKeys.ContainsKey(data.Id)) { //quiere cifrar o descifrar if (data.Cifrar) { msg = DicKeys[data.Id].Encrypt(data.Datos); } else { msg = DicKeys[data.Id].Decrypt(data.Datos); } } else { msg = MsgKeyNotInstalled; } msg = Data.GetResponse(data.Id, msg); // Send back a response. stream.Write(msg, 0, msg.Length); // Shutdown and end connection client.Close(); } } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); } finally { if (server != default) { // Stop listening for new clients. server.Stop(); } SaveKeys(); } }