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 cancel connection from the server? #27

Open
rightaway opened this issue Jan 20, 2018 · 1 comment
Open

How to cancel connection from the server? #27

rightaway opened this issue Jan 20, 2018 · 1 comment

Comments

@rightaway
Copy link

If the server is sending progress of a task, and it reaches 100%, how can the server close the connection to the client? I see there's ways for the client to close the connection but not sure how the server can do it with this package.

@debel27
Copy link

debel27 commented Jan 29, 2018

Despite its name, the client object that you receive from the 'connection' event represents the SSE connection on the server side.

You can call client.close() to end the connection from the server.

Be aware that, due to how the EventSource work, the browser will attempt to reconnect some time after the connection has been closed. To prevent the browser from reconnecting, the server should end the response with a 204 status code. This is however not feasible in your case, because at the time you would cancel the connection the 200 status code would have been already sent to the client. If you want to prevent browser from reconnecting, you can set a very large retry value as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants