oksse | extension library for OkHttp to create a Server-Sent Event | Notification library
kandi X-RAY | oksse Summary
kandi X-RAY | oksse Summary
OkSse is an extension library for OkHttp to create a Server-Sent Event (SSE) client. Server-sent events is a standard describing how servers can initiate data transmission towards clients once an initial client connection has been established. They are commonly used to send message updates or continuous data streams to a client.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Creates a new server sent event
- Performs a retry
- Enqueues a call to the service
- Prepares the HTTP call
- Initial connect method
- Opens the SSE
- Notifies the failure
- Closes the call
- Sets the read timeout
oksse Key Features
oksse Examples and Code Snippets
Community Discussions
Trending Discussions on oksse
QUESTION
I'm trying to create a client that can receive events from a server using SSE (server-sent events) and I'm using OkHttp3 to do that, combined with the OkHttp3-sse library (com.squareup.okhttp3:okhttp:4.1.0 & com.squareup.okhttp3:okhttp-sse:4.1.0).
I am able to connect to the server and receive the events just fine, but at some point in time, I want to disconnect the client and shutdown my application. That is were the problem is. The connection gets closed, but the application is not shutting down, probably due to the ConnectionPool
not closing.
As there is hardly any documentation on the use of the OkHttp3-sse library, I have tried to reverse engineer from the code what to do. I have tried to:
- call
RealEventSource.cancel()
which is disconnecting, but is hanging on a thread - call
OkHttpClient.dispatcher().cancelAll()
which is also disconnecting, but remains hanging on a thread - call
Response.close()
which is passed toEventSourceListener.onOpen()
As an alternative, I have looked at https://github.com/heremaps/oksse which has the RealServerSentEvent.close()
call which is doing what I expect. It closes the connection and stops all threads allowing the application to shutdown completely.
I have looked at the implementation of the RealServerSentEvent
class to see how the implementation differs from RealEventSource
. I think the difference is in the conditions of the read loop:
RealEventSource
line https://github.com/square/okhttp/blob/master/okhttp-sse/src/main/java/okhttp3/internal/sse/RealEventSource.kt#L75:
ANSWER
Answered 2019-Oct-08 at 22:41You're using the API correctly and OkHttp should be causing the read to fail with an IOException when the call is canceled. Obviously this isn't happening which I read as a bug in OkHttp.
Next steps: report the bug to OkHttp. If you can do so with an executable test case I'll make sure this gets fixed real soon.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install oksse
You can use oksse like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the oksse component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page