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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:01:04+00:00 2026-05-17T00:01:04+00:00

In ASIO, s it possible to create another socket that has the same source

  • 0

In ASIO, s it possible to create another socket that has the same source port as another socket?

My UDP server application is calling receive_from using port 3000. It passes the packet
off to a worker thread which will send the response (currently using a dynamic source port).

The socket in the other thread is created like this:

udp::socket sock2(io_service, udp::endpoint(udp::v4(), 0));

And responds to the original request using the sender_endpoint saved with the original packet.

What I’d like to be able to do is respond to the client using the same source port as the server is listening on. But I can’t see how that can be done. I get an exception if I try that saying address in use. Is it possible to do what I’m asking? The reason I want that is if I use dynamic ports, it means the clients need to add special firewall rules in windows to allow the reply packets to be read. I’ve found that if the source port is the same in the reply, windows firewall will allow it to pass back in.

  • 1 1 Answer
  • 1 View
  • 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-17T00:01:04+00:00Added an answer on May 17, 2026 at 12:01 am

    You should be able to use the SO_REUSEADDR socket option to bind multiple sockets to the same address. But having said that, you don’t want to do this because it’s not specified which socket will receive incoming data on that port (you would have to check all sockets for incoming data)

    The better option is just to use the same socket to send replies – this can safely be done from multiple threads without any additional synchronisation (as you are using UDP).

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

Sidebar

Related Questions

I am using boost::asio to create a server application, specifically the UDP APIs. Right
I am using boost::asio::ip::udp::socket to communicate. I use socket.receive_from(...) to receive messages from clients.
I understood that calling boost::asio::ip::tcp::socket::async_receive (or boost::asio::ip::tcp::socket::async_send ) two times may result in a
Possible Duplicate: How to check if socket is closed in Boost.Asio? Is there an
Is it possible to detach a native socket from Boost.ASIO's socket class? If so,
Boost asio has such socket connect api . I have such simple code: try
I am using boost::asio to make a socket network. The library has a number
I have a boost::asio based server which works fine, except that I'm trying to
I'm reading from a boost::asio::ip::udp::socket like this: using boost::asio::ip::udp; // ... char recv_buf[128]; udp::endpoint
I have a TCP server using boost asio. I have accepted a socket connection.

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.