I was wondering what the equivalent of the winsock dataarrival event is with the tcp client. I've looked on google and msdn, but i haven't been able to find any method that wrks like it. Thanks for any help
Printable View
I was wondering what the equivalent of the winsock dataarrival event is with the tcp client. I've looked on google and msdn, but i haven't been able to find any method that wrks like it. Thanks for any help
The class overview topic in the MSDN library has a code example of sending and receiving data using a TcpClient object.
that's the code that i'm using now. i packet sniffed it and it sends the request fine. it then receives the returned header and a small amount of data that appears to be gzip compressed, but i can't tell because it's 2 characters long. then i split it and it get the cookies properly, but it freezes on the gzip decompression. if someone could help me with why it doesn't receive all the data and the gzip decompression that would be great. thanksCode:TcpClient client = new TcpClient("google.com", 80);
Byte[] data = System.Text.Encoding.ASCII.GetBytes(strRequest);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
while (stream.DataAvailable == false)
{
Application.DoEvents();
}
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[1024]; //8192
string tempString = null;
int count = 0;
sb.Remove(0, sb.Length);
do
{
count = stream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
strSource = sb.ToString();
MemoryStream msCompressed = new MemoryStream(Encoding.UTF8.GetBytes(strSource));
byte[] buffer = new byte[msCompressed.Length];
GZipStream zipStream = new GZipStream(msCompressed, CompressionMode.Decompress);
byte[] decompressedBuffer = new byte[msCompressed.Length + 100];
int totalCount = ReadAllBytesFromStream(zipStream, decompressedBuffer);
msCompressed.Close();
zipStream.Close();
strSource = decompressedBuffer.ToString();
strHeaders = Regex.Split(strSource, Environment.NewLine + Environment.NewLine);
CookieString = GrabCookies(strHeaders[0], CookieString);
client.Close();
stream.Close();
return strHeaders[1];