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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:56:15+00:00 2026-05-27T13:56:15+00:00

I am having trouble using the connect() function. My code was completely working before,

  • 0

I am having trouble using the connect() function. My code was completely working before, but now I have moved to a different physical network and my blocking call to connect() no longer works, and just seems to hang indefinitely. Receiving broadcasts over UDP still works fine. Going back to the old network it works fine again. I cant for the life of me figure out why it works on one network and not the other. I have checked firewall settings and they are correct. What could be going on?

I have a pre-defined port being used and I am getting the address from the broadcast. I use recievefrom to receive the broadcast and set the outgoing ip address from it
ret = recvfrom (bcast, bcast_read,sizeof(j4cDAC_broadcast),0,(sockaddr*)&from,&size);

to.sin_addr = from.sin_addr;

local.sin_addr.s_addr = inet_addr("0.0.0.0");

Then for the TCP connection I have

dac = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

    //  cout << "SOCKET\n";
        if (dac == INVALID_SOCKET)
            {
            SetConsoleTextAttribute(console,(WORD)12);
            cout << "TCP socket failed: " << WSAGetLastError();
            connected_ = false;
            return(1);
            }

        //set SO_REUSEADDR on a socket to true (1):
        bool optval = true;

        setsockopt(dac, SOL_SOCKET,SO_DONTLINGER,(const char*)&optval, sizeof(optval)); 

        int pies = setsockopt(dac, SOL_SOCKET,SO_REUSEADDR,(const char*)&optval, sizeof(optval) );  

        if (pies == SOCKET_ERROR )
            {
            SetConsoleTextAttribute(console,(WORD)12);
            cout << "SETSOCKOPT ERROR: " << WSAGetLastError() << endl;
            }    // */
        local_T = local;
        local_T.sin_port =  htons ((short)TCPport);

        //bind the tcp socket
        bndt = bind(dac,(SOCKADDR*) &local_T,sizeof(local_T) );

        if (bndt == SOCKET_ERROR )
            {
            SetConsoleTextAttribute(console,(WORD)12);
            cout << "BIND TCP FAILED: " << WSAGetLastError();

            if (WSAGetLastError() == WSAEACCES)
                cout << "ACCESS DENIED";

            cout << endl;
            SetConsoleTextAttribute(console,(WORD)7);
            shutdown(dac,2);
            closesocket(dac);

            connected_ = false;
            return 1;
            }

        c = connect(dac, (sockaddr*) &to, size);      // <------- This hangs

        if (c == SOCKET_ERROR)
            {
            cout << "connection problem: " << WSAGetLastError() <<endl;
            }

        connected_ = true;`
  • 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-27T13:56:15+00:00Added an answer on May 27, 2026 at 1:56 pm

    I found this to be an issue with VMWare virtual networking devices. Even though I had no virtual machines running, after much testing of various things, I found the device broadcast was being received on one of the virtual networking interfaces from VMWare somehow. Disabling these two devices has fixed this issue.

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

Sidebar

Related Questions

I have to read data from mdb-files using c++ but I'm having trouble getting
I have a mobile application that I'm using with Facebook connect. I'm having trouble
I'm having trouble understanding how QGraphicsItemAnimation's setScaleAt function works. Here's the code I'm using:
I'm having some trouble using constraints correctly. I have three tables, 'item', 'store' and
I'm using BlazeDS to connect Flex with Java. I'm having trouble passing ArrayLists of
I'm having trouble with using a mysqli_query inside a function, error: Warning: mysqli_query() expects
I have been having some trouble lately with using custom classes as types. As
Im having trouble using a .NET COM in vb6, It compiles ok and I
I am using mssql and am having trouble using a subquery. The real query
I am having trouble using the attribute XPath Selector in ElementTree, which I should

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.