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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:33:32+00:00 2026-06-03T23:33:32+00:00

I discovered a problem in my code when I try to bind multiple sockets.

  • 0

I discovered a problem in my code when I try to bind multiple sockets. I try to explain the situation, I have an application consisting of two parts, one is written in C running on machine_1, the other one is in Java running on machine_2. The C program should be able to send udp-packets through one port to 4 ports on the machine_2 which is listening on them. Vice versa machina_2 should send udp-packets through one outgoing port to 4 corresponding ports on machine_1.

The problem I have is on machine_1:

  1. I have two threads there, one processing outgoing data to machine_2 and one processing the incoming data. Within the first thread (processing outgoing data) I create 4 sockets (with 4 different ports) to address the corresponding sockets on machine_2. Works fine in that direction…
  2. But when I try to create the sockets for the incoming data from machine_2, and I want to use the same port numbers as I did for incoming data on machine_2, but then I run into problems when I try to bind the sockets. Giving me the : Address already in use error.

I need some help on how to set up the socket configuration on machine_1 inside the C application for outgoing and incoming ports. And maybe an example on how to use the select() function to listen on all 4 incoming sockets.

If come code examples needed, I can add them here, but as I said it is only working for the thread_1 which handles the outgoing data through one socket to 4 different sockets on machine_2.

Thanks in advance for your help!

I hope the attached picture can explain the situation little bit more, important is that I want to use the same port numbers on both machines for incoming data. Means, port_1 on machine_1 has same port number than port_1 on machine_2, and so on…port_configuration

  • 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-03T23:33:34+00:00Added an answer on June 3, 2026 at 11:33 pm

    My advise is to just use 4 sockets. Sockets are bidirectional (that is if you really need 4 sockets, since this is UDP, one socket would probably be enough). Then you can share the sockets among several threads and read or write to them. You just need to be sure to synchronize whatever needs to be synchronize.

    Here’s an example on how to use select:

    http://www.lowtek.com/sockets/select.html

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

Sidebar

Related Questions

I have a code in production which crash one/two times per day, since one
I have a problem with bindings in wpf. I've discovered a strange problem. I
I have run into a rather weird little problem. In the following code I
I have discovered that in SQL Reporting there might be a problem. I have
I have problem with my transfer files application .. everything looks great and works
EDIT: I have now discovered the problem is with my WCF service getting dirty
This problem was discovered when I tried to run the Android emulator in Eclipse.
This question is already answered. I discovered what the problem is. But, I'm posting
Discovered something and am looking into a bit of incite as to why one
I have just discovered a variable name that is misspelled. If it were hidden

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.