Results 1 to 3 of 3

Thread: [2.0] tcpclient dataarrival?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    [2.0] tcpclient dataarrival?

    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
    Last edited by cx323; Jun 14th, 2006 at 01:29 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] tcpclient dataarrival?

    The class overview topic in the MSDN library has a code example of sending and receiving data using a TcpClient object.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    116

    Re: [2.0] tcpclient dataarrival?

    Code:
    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];
    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. thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width