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

  • SEARCH
  • Home
  • 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 562229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:31:56+00:00 2026-05-13T12:31:56+00:00

I have a socket wrapper class that sends and recieves messages with a server

  • 0

I have a socket wrapper class that sends and recieves messages with a server (specifically commands, responses, and notifications). I also have a consuming class that serializes the commands into text to send through the wrapper. My problem is that when a command is sent, I need to wait until I get a message back with a particular header. When I do this, the consuming class locks as I am using ManualResetEvent.WaitOne that is set by my receiving method. The reason it’s a problem when my consuming class locks is that another message might be received in the meantime and I cannot process it. Is there any way to lock a specific object so my class can still respond to other events?

Send method:

    _waitingCommands.Enqueue(command);
    String commandText = command.ToString();
    _socket.Send(commandText);

Receive method:

if (response.Header.Type == Messages.MessageType.Response)
{
   if (command.Response == null)
      command.Response = response;

   _waitingCommands.Dequeue();
   command.Finished.Set();
}
  • 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-13T12:31:57+00:00Added an answer on May 13, 2026 at 12:31 pm

    Use socket.BeginSend and socket.BeginReceive. These will spin off seperate threads that will allow your main thread to continue processing. Once the data is sent or recieved, the methods you hooked up to the BeginSend/BeginReceive method will fire, in logical order.

    Begin Send

    BeginReceive

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

Sidebar

Ask A Question

Stats

  • Questions 489k
  • Answers 489k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Django views are expected to return HttpResponse objects. Your view… May 16, 2026 at 8:59 am
  • Editorial Team
    Editorial Team added an answer Found the Solution :) just simple add: AdWhirlAdapter.setGoogleAdSenseAppName("Application Name"); AdWhirlAdapter.setGoogleAdSenseCompanyName("Developer… May 16, 2026 at 8:59 am
  • Editorial Team
    Editorial Team added an answer Having only insert, delete and move results in an NP-hard… May 16, 2026 at 8:59 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am thinking to write a simple wrapper class for socket in C++. I
I have an XML document coming in over a socket that I need to
I am developing a framework, and some of the objects have reaaally long names.
My RMI enabled application seems to be leaking sockets. I have a Java application
in a project we want to wrap the Boost Asio socket in a way,
Background: I am taking a class at my university called "Software Constraints". In the
I have two closely related classes which I'll call Widget and Sprocket. Sprocket has
Have seen this comment in a method: //I wonder why Sun made input and
I've asked here a ton of questions about WSAAsyncSelect and NET.Few months ago I

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.