|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Socket
A Socket represents a connection to a remote server. A Socket abstract the transport used and will negotiate
the best Request.TRANSPORT to communicate with the Server.
fire(Object)
method is invoked and cached for further re-use.
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(Request.TRANSPORT.WEBSOCKET) // Try WebSocket
.transport(Request.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.STATUS
The current state of the underlying Socket. |
| Method Summary | |
|---|---|
void |
close()
Close this Socket, asynchronously. |
Future |
fire(java.lang.Object data)
Send data to the remote Server. |
Socket |
on(Event event,
Function<?> function)
Associate a Function with an Event. |
Socket |
on(Function<?> function)
Associate a Function with the Socket. |
Socket |
on(java.lang.String functionMessage,
Function<?> function)
Associate a Function with the Socket. |
Socket |
open(Request request)
Connect to the remote Server using the Request's information. |
Socket |
open(Request request,
long timeout,
java.util.concurrent.TimeUnit unit)
Connect to the remote Server using the Request's information, will timeout if the connection failed to open
within a certain time. |
Socket.STATUS |
status()
Return the Socket.STATUS of this Socket. |
| Method Detail |
|---|
Future fire(java.lang.Object data)
throws java.io.IOException
Encoder, and then send to the server.
The server's response will be delivered to the set of defined Function using the opened Transport, e.g for
Request.TRANSPORT.WEBSOCKET, the same connection will be re-used and, for others transports, the suspended connection.
data - object to send
Future
java.io.IOExceptionSocket on(Function<?> 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(java.lang.String functionMessage,
Function<?> 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 Event but handling of custom message can be done using a FunctionResolver
function - a Function
Socket on(Event event,
Function<?> function)
Function with an Event. When the event happen the library will try to associated
the decoded event (decoded by Decoder) to the defined type of the Function. The default event
are defined by Event but handling of custom event can be done using a FunctionResolver
function - a Function
Socket open(Request request)
throws java.io.IOException
Request's information.
request - a Request
java.io.IOException - in case the connect fails or a network failure occurs.
Socket open(Request request,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.io.IOException
Request's information, will timeout if the connection failed to open
within a certain time.
request - a Requesttimeout - the maximum time to waitunit - the time unit of the timeout argument
java.io.IOException - in case the connect fails or a network failure occurs.void close()
Socket.STATUS status()
Socket.STATUS of this Socket.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||