Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 939875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:51:44+00:00 2026-05-15T21:51:44+00:00

I have a receive callback from an async client method that is supposed to

  • 0

I have a receive callback from an async client method that is supposed to call socket.BeginReceive internally to check if data is done being sent. The code is as follows:

    private void ReceiveCallback(IAsyncResult ar)
    {
        try
        {
            StateObject state = (StateObject)ar.AsyncState;
            Socket client = state.workSocket;
            int bytesRead = client.EndReceive(ar);

            if (bytesRead > 0)
            {
                state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
                client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, 
                    new AsyncCallback(ReceiveCallback), state);
            }
            else
            {
                if (state.sb.Length > 1)
                {
                    response = state.sb.ToString();
                }
                File.AppendAllText(DataDisplay.Properties.Settings.Default.rawDataLog, response + "\r\n");
                receiveDone.Set();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }

The problem with this is that when the code reaches the client.BeginReceive call, nothing happens. I know that sounds vague, so let me try to explain. I have set breakpoints throughout the code to see where it could possibly be going, and I can’t figure it out. I have tried the else case, the beginning of the ReceiveCallback, where the receivedone.Set() returns to in the main code, the catch statement, etc. to no avail.

The part that is most confusing is that when I run it with a test server I wrote, it works as I would expect. This code is essentially from the MSDN example on async sockets, in case it looks familiar. Only when I try it with the third party device, I get stymied.

Any ideas what could be going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:51:45+00:00Added an answer on May 15, 2026 at 9:51 pm

    Is it possible that while you are debugging, nothing is actually being received so its essentially permanently waiting on the receive thread? Note that BeginReceive will use a ThreadPool thread, and will callback to the method you post. If its not calling back, then my first impression is that its not received anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, we call BeginReceive and have the callback method that BeginReceive executes when
I have a WCF service that receive query from a silverlight client and send
I am trying to have my WCF client receive info from a callback. I
I have an application that may receive data via various methods and in various
I have a method that will receive a string , but before I can
I have a javascript interface class to receive some values from javascript. I toasted
I have an application where I receive each data 40.000 rows. I have 5
I have a User Interface that receives asynchronous notifications from a Service that prompts
I have a WF service that I'm trying to setup receive activities to Subscribe
I have an app that streams video from the net and plays it using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.