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 8229349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:46:10+00:00 2026-06-07T16:46:10+00:00

I have created an asynchronous server that can read in messages from any number

  • 0

I have created an asynchronous server that can read in messages from any number of clients. My server code is closely related to this example: http://msdn.microsoft.com/en-us/library/fx6588te.aspx

After a client connects I would like to periodically send out data to that client, maybe 2 or 3 times per second. I can’t think of a good way to achieve this with an asynchronous send(). I’m assuming that some sort of timing mechanism would need to be added to my AcceptCallback() method because that is where the connection to the client happens.

In the previous version of my server I used blocking sockets and just looped my send() method in an infinite while() loop and called sleep() to get the timing down.

Here’s what I’m thinking:

public void AcceptCallback(IAsyncResult ar)
    {
        allDone.Set(); // Signal the main thread to continue.

        // Get the socket that handles the client request.
        Socket listener = (Socket)ar.AsyncState;
        Socket handler = listener.EndAccept(ar);
        IPEndPoint remotePoint = (IPEndPoint)handler.RemoteEndPoint;
        IPAddress remoteAddress = remotePoint.Address;
        Console.WriteLine("Connected to {0}!", remoteAddress.ToString());

        // Create the state object.
        StateObject state = new StateObject();
        state.workSocket = handler;

        //Start periodically sending here??

        handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
            new AsyncCallback(ReadCallback), state);
    }
  • 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-06-07T16:46:12+00:00Added an answer on June 7, 2026 at 4:46 pm

    I would set up a Timer object to send data to the client. Instantiate and start the timer in the AcceptCallback method at your comment. You’ll have to keep track of information to allow that timer callback to send data to the client (like the socket, and some sort of test to allow it to stop–although you can simply turn the timer off, but you’d have to keep track of the timer in that case).

    BTW, never call Sleep in situations like this because that commits your thread to sitting around for some period of time and you can’t easily abort it to get the thread back (to exit or use for something else).

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

Sidebar

Related Questions

I have an asynchronous client and server application that wrap OpenSSL. Once created, they
Lets say I have a server program that can accept connections from 10 (or
I have created a function that shows/hides different messages according to a combination of
I need to develop a client server system where I can have multiple clients
I have created an Html 5 page that provides important server-side functionality. Unfortunately, it
I have an Android app that communicates with a server via asynchronous socket connection
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have created some JQuery that will expand a div 'popup' on hover and
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a dialog and got a problem that only part of the

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.