|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Socket
A Socket represent a connection to a remote server. A Socket abstract the transport used, the client will negotiate
the best Request.transport() to communicate with the remote Server. As simple as
Client client = AtmosphereClientFactory.getDefault().newclient();
RequestBuilder request = client.newRequestBuilder()
.method(Request.METHOD.GET)
.uri(targetUrl + "/suspend")
.encoder(new Encoder<String, Reader>() { // Stream the request body
@Override
public Reader encode(String s) {
return new StringReader(s);
}
})
.decoder(new Decoder<String, Reader>() {
@Override
public Reader decode(String s) {
return new StringReader(s);
}
})
.transport(WEBSOCKET) // Try WebSocket
.transport(LONG_POLLING); // Fallback to Long-Polling
Socket socket = client.create();
socket.on("message", new Function<String>() {
@Override
public void on(Reader r) {
// Read the response
}
}).on(new Function<IOException>() {
@Override
public void on(Throwable t) {
// Some IOException occurred
}
}).open(request.build()).fire("echo");
| Nested Class Summary | |
|---|---|
static class |
Socket.EVENT
|
| Method Summary | |
|---|---|
void |
close()
Close this Socket |
Future |
fire(Object data)
Send data to the remote Server. |
Socket |
on(Function<? extends Object> function)
Associate a Function with the Socket. |
Socket |
on(String functionMessage,
Function<? extends Object> function)
Associate a Function with the Socket. |
Socket |
open(Request request)
Connect to the remote Server using the Request's information. |
| Method Detail |
|---|
Future fire(Object data)
throws IOException
data -
Future
IOExceptionSocket on(Function<? extends Object> function)
Function with the Socket. When a response is received, the library will try to associated
the decoded message (decoded by Decoder) to the defined type of the Function
function - a Function
Socket on(String functionMessage,
Function<? extends Object> function)
Function with the Socket. When a response is received, the library will try to associated
the decoded message (decoded by Decoder) to the defined type of the Function. The default messages
are defined by Function.MESSAGE but handling of custom message can be done using a FunctionResolver
function - a Function
Socket open(Request request)
throws IOException
Request's information.
request - a Request
IOExceptionvoid close()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||