polling for socket Read.

This is a discussion on polling for socket Read. within the C# Programming forums, part of the General Programming Boards category; According to the : MSDN socket polling method SelectRead returns true on 3 occasions but I'm only interested in just ...

  1. #1
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271

    polling for socket Read.

    According to the : MSDN socket polling method SelectRead returns true on 3 occasions but I'm only interested in just the one; when there's data available for reading. Is there a way to poll a socket in C# so that I read the buffer only when this condition is satisfied?
    so far my method is:
    Code:
    private void recvMessage(ref TextBox mDest)
            {
                try
                {
                    int rcount;
                    if (active_connection)
                    {
                        if (m_sock.Poll(-1, SelectMode.SelectRead))
                        rcount = m_sock.Receive(recvBuffer);
                        mDest.Text += Encoding.ASCII.GetString(recvBuffer);
                                            
                        Array.Clear(recvBuffer, 0, recvBuffer.Length);
                        mDest.Text += "\r\n";
                        SendMessage(mDest.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
                    }
                    else
                        mDest.Text = "";
                }
    
                catch (SocketException se)
                {
                    MessageBox.Show(se.Message);
                }
    
            }
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    According to MSDN I wouldn't see why your method wouldn't work. Whenever something is true of the socket based on SelectMode.SelectRead, your thread will wakeup and call Receive.

  3. #3
    WDT
    WDT is offline
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    It works, but I only want it to wake up only when there's something to read in the buffer.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read() problems
    By yay4rei in forum C Programming
    Replies: 2
    Last Post: 07-21-2005, 10:47 AM
  2. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM
  3. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 03:32 PM
  4. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 02:49 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21