I want to listen to a running IceCast-Server, but it keeps getting 0 bytes only (although it gets a connection to IceCast).
What am I doing wrong?
Here is the code I use:
tcpClient = new TcpClient();
tcpClient.Connect(IPAddress.Parse("127.0.0.1"), 8000);
HandleClientComm(tcpClient);
And here HandleClientComm:
private void HandleClientComm(object client)
{
TcpClient tcpClient = (TcpClient)client;
NetworkStream clientStream = tcpClient.GetStream();
byte[] message = new byte[4096];
int bytesRead;
String acceptIcast = "HTTP/1.0 200 OK" + endl+endl;
clientStream.Write(StringToByteArray(acceptIcast),0,acceptIcast.Length);
OnTraktorConnection(new TraktorConnectionEventArgs(true));
while (true)
{
bytesRead = 0;
try
{
//blocks until a client sends a message
bytesRead = clientStream.Read(message, 0, 4096);
Debug.WriteLine(bytesRead);
}
catch
{
//a socket error has occured
break;
}
if (bytesRead == 0)
{
//the client has disconnected from the server
Debug.WriteLine("client has been disconnected");
break;
}
//message has successfully been received
ASCIIEncoding encoder = new ASCIIEncoding();
string response = encoder.GetString(message, 0, bytesRead);