Skip to content

Instantly share code, notes, and snippets.

@hiteshchopra11
Created April 23, 2022 19:55
Show Gist options
  • Save hiteshchopra11/1c49f196bf42dd47f5c5e4f38e8abdc2 to your computer and use it in GitHub Desktop.
Save hiteshchopra11/1c49f196bf42dd47f5c5e4f38e8abdc2 to your computer and use it in GitHub Desktop.
OkHttp Client and EventSourceFactory
val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.MINUTES)
.writeTimeout(10, TimeUnit.MINUTES)
.build()
val request = Request.Builder()
.url("https://test-sse-backend.herokuapp.com/events")
.header("Accept", "application/json; q=0.5")
.addHeader("Accept", "text/event-stream")
.build()
EventSources.createFactory(client)
.newEventSource(request = request, listener = eventSourceListener)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment