private void SendDirectoryFile(TcpClient tcpClient, string filePath) { TcpUtils.SendFileRequest(tcpClient); SendFileNodeDescription(tcpClient, filePath); string responseCommand; try { responseCommand = TcpUtils.ReceiveCommand(tcpClient, Constants.TRANSFER_TCP_ACCEPT.Length); } catch (Exception e) { MessageBox.Show("Timeout waiting for user response", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!responseCommand.Equals(Constants.TRANSFER_TCP_ACCEPT)) { ManageRefusedFile(filePath); return; } SendFileContent(tcpClient, filePath); }
public void Receive() { while (true) { // blocking call TcpClient client = _tcpServer.AcceptTcpClient(); Thread clientThread = new Thread(() => { String command = TcpUtils.ReceiveCommand(client, Constants.TRANSFER_TCP_FILE.Length); if (command.Equals(Constants.TRANSFER_TCP_FILE)) { ReceiveFile(client); } else { ReceiveDirectory(client); } client.Close(); }); clientThread.IsBackground = true; clientThread.SetApartmentState(ApartmentState.STA); clientThread.Start(); } }
public void SendDirectory() { TcpClient tcpClient = new TcpClient(_server, _port); // sending directory request TcpUtils.SendDirectoryRequest(tcpClient); // sending direcroty description DirectoryNode directoryNode = SendDirectoryNodeDescription(tcpClient); // gettin response string responseCommand = TcpUtils.ReceiveCommand(tcpClient, Constants.TRANSFER_TCP_ACCEPT.Length); if (!responseCommand.Equals(Constants.TRANSFER_TCP_ACCEPT)) { ManageRefusedDirectory(_path); return; } // sending directory content SendDirectoryContent(directoryNode, _path); tcpClient.Close(); }