I am making a program on Visual C#, attempting to connect to a Shoutcast radio and download the audio. However, I get a protocol violation error on the GetResponse() function. I've heard that Shoutcast is not a common HTTP protocol, and I didn't find any data related to special connections. I have something like this in my code:
private void downloadPart()
{
System.Net.WebRequest conn;
System.Net.WebResponse connResp;
System.IO.Stream readStream = null;
System.IO.FileStream writeStream;
int bufferSize = 8192;
try
{
conn = System.Net.WebRequest.Create(this.caminhoURL);
connResp = conn.GetResponse();
readStream = connResp.GetResponseStream();
writeStream = new System.IO.FileStream(@"C:\", System.IO.FileMode.Create, System.IO.FileAccess.Write);
int length;
byte[] buffer = new Byte[bufferSize];
do
{
length = readStream.Read(buffer, 0, bufferSize);
writeStream.Write(buffer, 0, length);
System.Diagnostics.Debug.WriteLine("Working");
readStream.Flush();
} while (length > 0);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.StackTrace);
}
finally
{
if (fluxoLeitura != null)
{
fluxoLeitura.Close();
System.Diagnostics.Debug.WriteLine("Done");
}
}
}
I have tested this function to download a simple file and it worked. I know that the stream is continuous so I can't download it all in a single file, I just need to know how to configure the connection. How should I do this?