I have the following code using the TcpClient
byte[] encbuff = System.Text.Encoding.UTF8.GetBytes("username" + ":" + "password");
string follow = "track=soccer,twitter";
byte[] encode_follow = System.Text.Encoding.UTF8.GetBytes(follow);
using (TcpClient client = new TcpClient())
{
string requestString = "POST /1/statuses/filter.json HTTP/1.1\r\n";
requestString += "Host: stream.twitter.com\r\n";
requestString += "User-Agent: www.site.com\r\n";
requestString += "Referer: http://www.site.com\r\n";
requestString += "Content-Type: application/x-www-form-urlencoded\r\n";
requestString += "Authorization: " + "Basic " + Convert.ToBase64String(encbuff) + "\r\n";
requestString += "Content-length: " + follow.Length + "\r\n";
requestString += "Connection: keep-alive\r\n";
requestString += "\r\n";
requestString += follow;
requestString += "\r\n\r\n";
client.Connect("stream.twitter.com", 80);
//client.ReceiveTimeout = 100;
using (NetworkStream stream = client.GetStream())
{
// Send the request.
StreamWriter writer = new StreamWriter(stream);
writer.Write(requestString);
writer.Flush();
// Process the response.
StreamReader rdr = new StreamReader(stream);
while (!rdr.EndOfStream)
{
Console.WriteLine(rdr.ReadLine());
Console.WriteLine("IS end: " + rdr.EndOfStream.ToString());
}
}
}
What happens though is that the Console.WriteLine(rdr.ReadLine()); line will print out statuses for a few seconds than it would stop + not hit the break point there anymore, even though it's still connected.
What it should be doing is continuing to write the statuses in the console, since it's a keep-alive connection and the 'Twitter' keyword gets mentioned a few times every few seconds continuously.
Any ideas what could be causing this issue?