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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:36:37+00:00 2026-05-31T15:36:37+00:00

As part of a simple networking project I’m trying to connect two computers together

  • 0

As part of a simple networking project I’m trying to connect two computers together to send a simple data packet. The client uses a broadcast to find servers, and my server successfully detects this broadcast from the client.

The server then sends a reply packet, however I am unable to get the client to listen to the packet.

The problem seems to lie with the broadcasting method, since if I use a direct server connection, aka instead of INADDR_BROADCAST I specify the IP address 127.0.0.1 or 192.168.0.x then the server connects, sends a reply, and the client receives it.

The listening code in the client:

// Stop the client from waiting for packets if there are none.
fd_set checksockets;
checksockets.fd_count = 1;
checksockets.fd_array[0]=m_listenSocket;
struct timeval t;
t.tv_sec=0;
t.tv_usec=0;
int waiting = select(NULL, &checksockets, NULL, NULL, &t);

// If there is at least one packet receive it.
if(waiting>0) {
    std::cout << "Packet received.\n";
}

From this point I attempt to find the server address with the recvfrom() method.

I’ve made sure to use the broadcast flag on the client socket, right after creating it. This returns no errors.

int value=true;
int result = setsockopt(m_socket, SOL_SOCKET, SO_BROADCAST, (char*)&value, sizeof( value ) );

I’ve checked all possible WINSOCK functions that I’ve used and none return any errors.

I’ve also tried creating a second socket only for listening on the same port, but this conflicts with the server and therefore fails to open.

So essentially, what I’m trying to ask: How can I have a client listen for a reply from a broadcast? – aka the server address is unknown at first, I’m attempting to create a new socket using the reply address, however I’m not getting a reply address from a broadcast, despite the server receiving the broadcast and definitely sending a reply.

  • 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-31T15:36:38+00:00Added an answer on May 31, 2026 at 3:36 pm

    As you point out you won’t receive any back when bound to INADDR_BROADCAST. This is normal: when you are bound to an address you only receive packets from that address. You don’t need to bind the sockets to any address at all. This operation is usually required for connected sockets (i.e. TCP). If the receiving socket works I guess it is because you’re doing all your tests on the same machine.

    If you want to receive packets from a given address you can try to use connect or sendto and receivefrom.

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

Sidebar

Related Questions

As part of a larger web-app (using CakePHP), I'm putting together a simple blog
I'm trying to implement a fairly simple card game in Python so that two
I am trying to create a very simple application (part of my learning program),
I have to write a program that sniffs network packets (part1-the simple part). And
I want to implement a simple 2 part FormWizard. Form 1 will by dynamically
This module is part of a simple todo app I made with Python... def
I have a simple model class (Part), which pulls from it's information from a
I am creating a simple blog as part of a website and I am
As a part of our application I need to write simple workflow system which
I'm developing a simple application to manage the operational part of a business using

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.