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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to determine a message has been fully transfered #106

Closed
slince opened this issue May 31, 2017 · 7 comments
Closed

How to determine a message has been fully transfered #106

slince opened this issue May 31, 2017 · 7 comments
Labels

Comments

@slince
Copy link

slince commented May 31, 2017

Hi,

I have created a server socket;

        $this->socket->on('connection', function(ConnectionInterface $connection){
               $connection->on('data', function($message) {
                   $this->createHandler($message, $connection)->handle($message);
               });
        });
        $this->socket->on('error', function($exception){
            $this->dispatcher->dispatch(new Event(EventStore::SOCKET_ERROR, $this, [
                'exception' => $exception
            ]));
        });
        $this->loop->run();

If a socket client send large chunks of data(greater than 65535) to the server. the listener for the event "data" will only get partial content every time.
How to gather all the partial content into a complete message?

@cboden
Copy link
Member

cboden commented Jun 1, 2017

You need to implement a protocol on top of the TCP layer. By design TCP is an open ended stream that sends and receives chunks. HTTP, RFC6455, ZMQ, and STOMP are a few examples. Something simpler might be to try JSON streaming

@cboden cboden added the question label Jun 1, 2017
@slince
Copy link
Author

slince commented Jun 2, 2017

@cboden Hi, i have understand。
However when I tried to study how "react / http" caught the http message, the package did not reach my expectations.

You will find that the http request body seems to be empty:

image

Is it because the full http request message is not caught?

@cboden
Copy link
Member

cboden commented Jun 4, 2017

ping @WyriHaximus

@WyriHaximus
Copy link
Member

@slince we're working on full PSR-7 support for until then the request section on react/http on how streaming the body in works: https://github.com/reactphp/http#request

@slince
Copy link
Author

slince commented Jun 5, 2017

@WyriHaximus
Ok.
I think the "connection" event should be emitted when the full http message is caught(includes http header and body). You know that almost every request has a body.

@WyriHaximus
Copy link
Member

the full http message is caught(includes http header and body)

And there lies the problem. We also support websockets where the 'body' is never done. Another thing is that if a client sends a huge file buffering that would mean loading it all into memory. And for one request that isn't to much of an issue, it becomes an issue when 10s or 100s of clients do that at the same time. Nowreact/http v0.8.0 will bring body parsers in the way you suggest: reactphp/http#120

@clue
Copy link
Member

clue commented Jun 14, 2017

I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can reopen this 👍

@clue clue closed this as completed Jun 14, 2017
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

4 participants