Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to listing on socket, works in some cases not in all #18

Closed
LEDfan opened this issue Jun 5, 2015 · 6 comments
Closed

Trying to listing on socket, works in some cases not in all #18

LEDfan opened this issue Jun 5, 2015 · 6 comments
Labels

Comments

@LEDfan
Copy link

LEDfan commented Jun 5, 2015

Hi, thanks for this project 馃槂.

I'm using this code from the README.md, with a small adjustment to output any data send to it.

    $loop = React\EventLoop\Factory::create();

    $socket = new React\Socket\Server($loop);
    $socket->on('connection', function ($conn) {
    echo "New connection " . $conn->getRemoteAddress() . "\n";


        $conn->on('data', function ($data) use ($conn) {
        echo "New msg from " . $conn->getRemoteAddress() . " msg: " . $data . "\n";
           $conn->close();
        });
    });
    $socket->listen(1337);

    $loop->run();

This works perfect if you start a netcat shell: nc localhost 6461, and type some data into it. However when I try to pipe some data to netcat e.g. echo "test" | nc localhost 6461, the connection is received (I see the new connection msg and ip address). However the data isn't received.

Is this normal behaviour or is this a bug? I'm trying to "catch" output from an existing service, which I can't change.

Thanks! (If you give me some hints where the bug is, I'll be happy to open a PR)

@LEDfan
Copy link
Author

LEDfan commented Jun 5, 2015

The end event on the $conn object is called directly after executing the netcat command.

@LEDfan
Copy link
Author

LEDfan commented Jun 5, 2015

BTW this is the perl code which I try to use: https://github.com/stevenshiau/clonezilla/blob/master/bin/ocs-socket by issuing ocs-socket -h ip -p 6461 -m test. This doesn鈥檛 works the first time, but it does the second time.

@LEDfan
Copy link
Author

LEDfan commented Jun 5, 2015

I think I found the problem: http://stackoverflow.com/questions/15163778/perl-tcp-client-does-not-display-incoming-data & http://stackoverflow.com/questions/993217/php-to-perl-socket-communication.
React is waiting for a full line, but per/netcat doesn't send it. However simply sending "\n" doesn't works.

@LEDfan
Copy link
Author

LEDfan commented Jun 5, 2015

馃巻 just looked at it again, and my assumption in the last post was correct, in the code I fetched via composer there is this:

if ('' === $data || false === $data || feof($stream)) {

Which checks if there is and end of file before emitting the data.

However in this code repo there is this line https://github.com/reactphp/socket/blob/master/src/Connection.php#L14

Which works perfect 馃槂. So the problem was I was using and old ratchet/react version.....

@LEDfan LEDfan closed this as completed Jun 5, 2015
@staabm
Copy link

staabm commented Jun 5, 2015

@LEDfan Was it a typo in your composer.json (version constraint) or does the latest version which is provided by composer/packagist not contain the correct line?

@LEDfan
Copy link
Author

LEDfan commented Jun 5, 2015

@staabm I first had:

   "require": {
        "cboden/Ratchet": "0.3.*",
        "react/zmq": "0.2.*",
        "phpseclib/phpseclib": "2.0.*@dev"
    }

Now I have:

   "require": {
     "cboden/ratchet": "0.3.*",
    "react/zmq": "0.3.*",
    "phpseclib/phpseclib": "0.3.*"
  }

@clue clue added the question label Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants