public class OkSse extends Object
The usage of this class follows the same logic as any OkHttp request.
Use new OkSse() to create a new instance with a new instance of OkHttpClient with default settings
// The singleton HTTP client.
public final OkSse okSseClient = new OkSse();
Use new OkSse(okHttpClient) to create a new instance that shares the instance of OkHttpClient.
This would be the prefered way, since the resources of the OkHttpClient will be reused for the SSE
// The singleton HTTP client.
public final OkSse okSseClient = new OkSse(okHttpClient);
To create a new ServerSentEvent call newServerSentEvent(Request, ServerSentEvent.Listener)
giving the desired Request. Note that must be a GET request.
OkSse will make sure to build the proper parameters needed for SSE conneciton and return the instance.
| Constructor and Description |
|---|
OkSse()
Create a OkSse using a new instance of
OkHttpClient with the default settings. |
OkSse(okhttp3.OkHttpClient client)
Creates a new OkSse using the shared
OkHttpClient |
| Modifier and Type | Method and Description |
|---|---|
okhttp3.OkHttpClient |
getClient()
Get the
OkHttpClient used to create this instance. |
ServerSentEvent |
newServerSentEvent(okhttp3.Request request,
ServerSentEvent.Listener listener)
Create a new instance of
ServerSentEvent that will handle the connection and communication with
the SSE Server. |
public OkSse()
OkHttpClient with the default settings.public OkSse(okhttp3.OkHttpClient client)
OkHttpClientclient - public okhttp3.OkHttpClient getClient()
OkHttpClient used to create this instance.OkHttpClientpublic ServerSentEvent newServerSentEvent(okhttp3.Request request, ServerSentEvent.Listener listener)
ServerSentEvent that will handle the connection and communication with
the SSE Server.request - the OkHttp Request with the valid information to create the connection with the server.listener - the ServerSentEvent.Listener to attach to this SSE.ServerSentEvent that will automatically start the connection.Copyright © 2018. All rights reserved.