public abstract class Endpoint extends Object
Here is an example of a simple endpoint that echoes any incoming text message back to the sender.
public class EchoServer extends Endpoint {
public void onOpen(Session session, EndpointConfig config) {
final RemoteEndpoint remote = session.getBasicRemote();
session.addMessageHandler(new MessageHandler.Whole<String>() {
public void onMessage(String text) {
try {
remote.sendString("Got your message (" + text + "). Thanks !");
} catch (IOException ioe) {
// handle send failure here
}
}
});
}
}
Constructor and Description |
---|
Endpoint() |
Modifier and Type | Method and Description |
---|---|
void |
onClose(Session session,
CloseReason closeReason)
This method is called immediately prior to the session with the remote
peer being closed.
|
void |
onError(Session session,
Throwable thr)
Developers may implement this method when the web socket session
creates some kind of error that is not modeled in the web socket protocol.
|
abstract void |
onOpen(Session session,
EndpointConfig config)
Developers must implement this method to be notified when a new conversation has
just begun.
|
public abstract void onOpen(Session session, EndpointConfig config)
session
- the session that has just been activated.config
- the configuration used to configure this endpoint.public void onClose(Session session, CloseReason closeReason)
session
- the session about to be closed.closeReason
- the reason the session was closed.public void onError(Session session, Throwable thr)
There are a number of categories of exception that this method is (currently) defined to handle:
SessionException
sDecodeException
ssession
- the session in use when the error occurs.thr
- the throwable representing the problem.Copyright © 2015 JBoss by Red Hat. All rights reserved.