What causes the error [could not bind to "tcp://127.0.0.1:8843". Cannot assign request Adress]?

Asked

Viewed 263 times

1

Come on. I have a PHP script that serves to create a websocket server for my application. I am using HTML5 websocket.

To create the server, I am using the Ratchet library found on the site socketo.me.

I run this code below from the command line:

 list ($host, $port) = $argv + ['localhost', 9000];

 $app = new Ratchet\App($host, $port, '0.0.0.0');

 $app->route('/chat', new Chat, array('*'));

 $app->route('/notificador', new Notificador, array('*'));

 $app->run();

Everything was working perfectly. Suddenly, this service stopped working. I tried to use the same command to start it again, but the following message is always displayed:

Could not bind to tcp:/127.0.0.1:8843: Cannot assign requested address

It is important to explain that I do not use port 8843 to run this script, I use port 9000. But the Ratchet library uses.

An excerpt from the class builder Ratchet\App:

    if (80 == $port) {
        $flashSock->listen(843, '0.0.0.0');
    } else {
        $flashSock->listen(8843);
    }

In turn the method listen has the following excerpt:

   $this->master = @stream_socket_server("tcp://$host:$port", $errno, $errstr);
    if (false === $this->master) {
        $message = "Could not bind to tcp://$host:$port: $errstr";
        throw new ConnectionException($message, $errno);
    }

The weird thing is, I already called the people at dialhost, where we have the hosting and it has been verified that there is no no service running on that door. So it wouldn’t be a "the door is already occupied".

What I’ve tried to do?

  • I asked to restart the server (Linux).

  • The dialhost employee said the door is not occupied. He claimed to have checked this via command telnet.

  • I’ve already executed the command fuser -k 8843/tcp to try to kill some process that was occupying this door.

  • I have done the process using a port in use (on purpose), to see if the returned message would be different, and returned different:

Could not bind to tcp://0.0.0.0:9001: Address already in use

... but nothing solved!

And now, who can help me?

  • 4
  • Does not have any firewall or proxy blocking the traffic of this port?

  • @Bacco I think he used the stun horn on this door. Ask him to press it twice to undo the effect :)

  • I am voting to close this question as out of scope because Wallace asked.

1 answer

1

Problem solved. Hosting employee said the problem was that the loopback interface was not running.

The interesting thing is that, as disassembled in the question, the section that uses the function listen demonstrates that if you do not pass the second parameter, 127.0.0.1 would be added.

The function stream_socket_server only worked with 0.0.0.0.

So, after he started that loopback thing, everything went back to working perfectly, like before.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.