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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:49:13+00:00 2026-05-23T00:49:13+00:00

I have written a TCP/IP program, in which the client uses ordinary (non-Boost) socket

  • 0

I have written a TCP/IP program, in which the client uses ordinary (non-Boost) socket API; i.e. the server binds and listens, and the client connects. The server uses pthreads to handle several clients at a time.

The program uses OpenSSL to exchange session keys between the client and the server.

Later, I noticed that periodically, I need to perform a “re-key”: After the session is established, I have to schedule a re-key task, in which the client and the server agree upon a new session key.

One option was to create a new thread for each client: The new thread will sleep for a period of time, and then awakens and initiates a re-key. This option is rather expensive, since each client needs to be multi-threaded.

Another option was to use Boost Asio. I regret I wasn’t aware that this valuable library existed; otherwise, I’d coded the program using Boost’s threads and Boost’s sockets.

Anyway, I want to do the job with minimum change. At first, I misunderstood Asio. Using Boost’s Timer 2 example, I wrote something like this:

void rekey(const boost::system::error_code& /*e*/)
{
  // do rekey
}

...

void main()
{
//connect to server

// schedule re-key
boost::asio::io_service io;    
boost::asio::deadline_timer t(io, boost::posix_time::minutes(30));
t.async_wait(rekey);    
io.run();

// the rest of job (i.e. sending and receiving messages in a while() loop.)
}

This is clearly wrong, since Boost blocks at io.run(). My first perception was that the asynchronous nature of async_wait will solve the problem, but clearly I misunderstood the Asio model.

I have two solutions in mind:

  1. Generate a function in which sending and receiving is performed (using ordinary socket API), and add this function to the queue of io object, so that io.run() works as expected.
  2. Re-write the socket functions using Boost’s asynchronous socket API.

Is there a better solution? In any case, could you please help me figure out how to implement the best solution?

  • 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-23T00:49:13+00:00Added an answer on May 23, 2026 at 12:49 am

    Generally, io_service::run() (or the other functions that cause events to happen such as io_service::poll(), io_servive::run_one() and io_service::poll_one()) would be run in their own thread.

    I’m a big proponent of the boost::asio library, as once you are used to coding with it, it is a very elegant and powerful library. However, if you already have a large portion of the application written (and working) I would not suggest rewriting it just to take advantage of boost::asio, especially if you only need some type of asynchronous timer.

    Since you stated that each client already has its own thread, I’d suggest using some type of sentinel that you periodically check in that thread to indicate when the re-key was necessary.

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

Sidebar

Related Questions

I have written a C# server which listens for Tcp connections. A client can
I have a client/server program in TCP written in C, and I would like
In sockets I have written the client server program. First I tried to send
I have written a very simple socket server. It listens in post 63254. First
I have written a TCP server implementation using which I created an application which
I have written a simple TCP client and server. The problem lies with the
I have a TCP/IP server written in C# .net which can have 10,000 connections
I have written a TCP server using the Socket class's asynchronous/IOCP methods, BeginSend()/BeginRead()/etc. I
I have a program (written in C/C++) that behaves as a socket server. I'd
I have written C code for a TCP server to listen to one client

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.