private static void SendMessage() { while (!finishChat) { while (!sendingFile && !recievingFiles) { string message = Console.ReadLine(); string messageToSend = $"{message}"; protocol.SendData(messageToSend, clientSocket); if (messageToSend[0] == '/') { if (messageToSend.Contains(" ")) { string[] splitedMessage = messageToSend.Split(' '); if (messageToSend.Split(' ')[0].Equals("/send")) { string filePath = GetFilePath(messageToSend); FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read); int noOfPackets = protocol.CalculateNoOfPackets(file); protocol.SendData("" + noOfPackets, clientSocket); protocol.SendFile(file, clientSocket); } } if (messageToSend.Equals("/files")) { recievingFiles = true; } } } } }
private static void OfferFile(SentFile fileToSend, TcpClient clientSocket, Chat currentChat) { bool waitingAnswer = true; while (waitingAnswer) { var userResponse = protocol.RecieveData(clientSocket); if (userResponse.Equals("si")) { StartQueue(); SendToQueue("Un usuario acepto un archivo"); waitingAnswer = false; protocol.SendData("1", clientSocket); FileStream file = new FileStream(fileToSend.FileServerPath, FileMode.Open, FileAccess.Read); int noOfPackets = protocol.CalculateNoOfPackets(file); protocol.SendData("" + noOfPackets, clientSocket); protocol.SendData(fileToSend.FileName, clientSocket); protocol.SendFile(file, clientSocket); } else { if (userResponse.Equals("no")) { waitingAnswer = false; protocol.SendData("2", clientSocket); StartQueue(); SendToQueue("Un usuario rechazo un archivo"); } else { protocol.SendData("3", clientSocket); } } } }