private void button2_Click(object sender, EventArgs e) { string[] files= null; string appPath = Path.GetDirectoryName(Application.ExecutablePath); //folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop; folderBrowserDialog1.SelectedPath = @"C:\MyMusic\"; DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.mp3"); songFolderTxtbox.Text = folderBrowserDialog1.SelectedPath; } IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(s), 81); TcpClient client = new TcpClient(); client.Connect(serverEndPoint); NetworkStream targetStream = client.GetStream(); InitializeTheConnection(targetStream, "password", null); if (files != null) { foreach (string filename in files) { using (Stream ms = new MemoryStream()) { using (Stream stream = new FileStream(filename,FileMode.Open)) { byte[] buffer = new byte[65536]; int read; while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) { System.Threading.Thread.Sleep(1000); //ms.Write(buffer, 0, read); targetStream.Write(buffer, 0, read); } } while (ms.Length < 65536 * 10) System.Threading.Thread.Sleep(1000); targetStream.Flush(); ms.Position = 0; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)