Boost logo

Boost Users :

From: Alexander Carôt (alexander_carot_at_[hidden])
Date: 2022-01-14 21:50:55


Hello all,

I have a problem with a a casually blocked UDP bind port: My application uses UDP port 50050 and initiates the socket this way:

udp::resolver resolver(dFC->myIoService);
int port = 50050;
bool failed;

do{
    failed = false;
    udp::resolver::query query(udp::v4(), IPAddress, port);
    try {
        dFC->s = new udp::socket(
            dFC->myIoService, udp::endpoint(*resolver.resolve(query)));
    } catch (std::exception &e) {
          
    failed = true;
    int intPort = this->intConverter(port);
    intPort++;
    ostringstream conv;
    conv << intPort;
    port = conv.str();
 
    cout << "new port: " << port << endl;
} while (failed);

So I am basically using bind port 50050 and if it fails I am increasing it by one until the bind suceeds. In most cases the bind to port 50050 works fine but casually after a relaunch of the app or a crash the bind port 50050 appears to be blocked which is why it increases to higher numbers.

Now I wonder how the port can still be taken although the app has terminated and if there is way to force the app / the OS using port 50050 ? So far I have seen this on OSX only – on Windows and Linux I haven't noticed it yet.

Thanks in advance for any pointer how to resolve my isse,
best

Alex

--
http://www.carot.de
Email : Alexander_at_[hidden]
Tel.: +49 (0)177 5719797

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net